I have lot's of outputLabel and inputText pairs in panelGrids
<h:panelGrid columns="2">
<h:outputLabel value="label1" for="inputId1"/>
<h:inputText id="inputId1/>
<h:outputLabel value="label2" for="inputId2"/>
<h:inputText id="inputId2/>
...
</h:panelGrid>
I want to have some behaviour for all of them: like same validation or same size for every inputText. So I have created a composite component which just includes an outputLabel and and an inputText
<my:editField value="field1"/>
<my:editField value="field2"/>
But now when I put them in a gridPanel, they do not get aligned depending on the length of the label text. I understand why, but I don't know how to work around.
There should have been a switch in panelGrid to render composite components separately. I have a solution for this. You can have separate composite components instead of clubbing them together. In each composite component you can use ui:fragments to demarcate the components you want to separately fall under different columns. Following is extract from my inputText.xhtml:
Now this will not going to align in the form which is inside the panelGrid:
So i have extended the GroupRenderer's encodeRecursive method, to add after label and a before field:
A composite component gets indeed rendered as a single component. You want to use a Facelet tag file instead. It gets rendered exactly as whatever its output renders. Here's a kickoff example assuming that you want a 3-column form with a message field in the third column.
Create tag file in
/WEB-INF/tags/input.xhtml
(or in/META-INF
when you want to provide tags in a JAR file which is to be included in/WEB-INF/lib
).Define it in
/WEB-INF/example.taglib.xml
(or in/META-INF
when you want to provide tags in a JAR file which is to be included in/WEB-INF/lib
):Declare the taglib usage in
/WEB-INF/web.xml
(this is not needed when the tags are provided by a JAR file which is included in/WEB-INF/lib
! JSF will auto-load all*.taglib.xml
files from/META-INF
).(multiple taglib files can be separated by semicolon
;
)Finally just declare it in your main page templates.
(the
#{bean.countries}
should return aMap<String, String>
with country codes as keys and country names as values)Screenshot:
Hope this helps.