0

I can't find any guidance on this question. I am writing a composite component that needs its own backing bean because 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?

4

1 回答 1

1

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.

于 2011-08-23T19:16:07.547 回答