开发者

Basic question about backing beans for Composite Components

I can't find any guidance on this question. I am writing a composite component that needs its own backing bean bec开发者_开发知识库ause it interacts with a data base.

The new component also needs to be able to set a value in some other backing bean as the result of some user action.

To do this, the question is do I have to write a @FacesComponent java class or a regular @Model/@Named (I use CDI annotations) type of bean? If you can use either, what is the advantage of one or the other?

Secondary question: will I be able to use CDI @Inject into a @FacesComponent to get my DAOs and such?

Update: I discovered that I can access cc.attr objects with the following code in a regular backing bean:

  FacesContext fc = FacesContext.getCurrentInstance();
  Object obj = fc.getApplication().evaluateExpressionGet(fc, 
            "#{cc.attrs.model.location}", Location.class);

So this allows me to obtain attributes. I haven't found out how I can write them yet.

So it seems that the only real reason to do a @FacesComponent is if you want to write rendering code that will output something the normal Facelets tags won't render. Is this correct?


I think BalusC responded to this basic question in this thread.

The main advantage is the ability of a @FacesComponent to access attributes that a UIComponent normally has access to, rather than trying to tie in with EL expressions executed in the bean.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜