JSF Composite Component

JSF Composite Component


Since JSF 2.0 , JSF provides a powerful concept of creating custom component using composite component along with JSF facelet tags . A composite component is a special type of component which acts as a reusable component . It helps developer to define a customized component having a particular high level behavior as well as structure along with Labels , attributes , validators , converters and Listeners . User can use that predefined structure and inject their own set of functionality like any other standard reusable components.

As per java specification , most commonly used composite tags are listed below :

Composite_Component tags.png
For simplicity, you can think composite:interface as java interface which is used to define a high level abstraction of the entire reusable component . Those configurable values are used in composite:implementation #{cc.attrs.attribute-name} expression to implement those values with reusable standard components .

Let’s discuss this tags with one practical example . Consider we have so many form required in our application of same types and number of components inside the form . So to define a form every time all over the application , it is easier to define a custom component of form and reuse it wherever it is required.

commonForm.xhtmlCommonForm.png
Here cc is a reserved keyword in JSF for composite component . We can access attributes defined under composite interface using syntax #{cc.attrs.<attribute-name>} . Now commonForm.xhtml is paced under the folder /resources/commonComponent under the application web root folder. Then we can use this component using namespace http://java.sun.com/jsf/composite/commonComponent .

Register Email.png

Comments

Popular posts from this blog

HashMap

What is Stream API in Java

HashMap internal working principle