开发者

Is it posssible to extend/override component class, that "cc.myFunc" will be available in facelet?

I've already asked here two questions about the subject, but the answers was uninformative. May be I did not explain well, what I want. Now, I will be more specific. I know that "Composite components are a Facelets feature, not a JSF feature", I know that "Fa开发者_JAVA百科celets is that Facelets is a view technology which is designed with JSF in mind". I don't know exactly, but I guess that abbreviations "cc.attrs" and "cc.clientId" assume, that there is some java class for component, behind the scene. I want to know, if it is possible to override/extend it in such way that "cc.myFunc" will be available?


You can provide a custom class for a composite component. The requirement is that the class has to be an UIComponent and implement the interface NamingContainer. There is a base class UINamingContainer that you can extend.

To declare it in your composite use something like:

<cc:interface componentType="my.CustomComponent">
</cc:interface>

The class could be something like:

@FacesComponent("my.CustomComponent") //Component type in the composite
public class AComponent extends UINamingContainer{
     private int a;      

     //setter and getter for a

     public void sayHello(){
        System.out.println("Hello");
     }

}

Note that the value of componentType attribute is the value of FacesComponent annotation.

In the implementation of your composite component, you would use #{cc.sayHello()}. The parentheses are required because without them the Facelets ELResolver would try to look for an attribute sayHello.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜