Question

I've started my own custom taghandler (pure XHTML, no Renderer) using BalusC's template, let's call it bean:input - the typical label, input, message trio. It's used like this:

<h:panelGrid columns="3">
   <bean:input label="input1:" bean="#{bean1}" property="name" />
   <bean:input label="input2:" bean="#{bean2}" property="name" />
   <bean:input label="input3:" bean="#{bean3}" property="name" />
</h:panelGrid>

Trouble is, the inputs are mutually exclusive (ie, only one of them should appear). Which input is shown is determined at render time by a view parameter. How do I do this?

I can't use <ui:fragment> as this would mess up the panelGrid, specifying rendered="false" on the tag had no effect and I kind of hesitate to wrap my tag implementation in a big <c:if test="#{rendered}"> - is there a better/builtin way to tell JSF it should simply skip rendering this specific tag?


Note: the <c:if> tag does funny things (like rendering a label that shouldn't be rendered, but not the corresponding input box) when I re-render the grid with a partial update. Adding the rendered attribute to the components themselves fixes that.

Was it helpful?

Solution

Add support for rendered attribute to the tag file and re-apply it on tag file's contents.

<bean:input label="input1:" bean="#{bean1}" property="name" rendered="..." />

I kind of hesitate to wrap my tag implementation in a big <c:if test="#{rendered}">

It's maybe ugly, but yes that's a way.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top