2

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.

Community
  • 1
  • 1
mabi
  • 5,279
  • 2
  • 43
  • 78

1 Answers1

1

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.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • "Adding support" here means applying it to all child components or plain `` in the custom tagfile? – mabi Jul 04 '13 at 15:18
  • 1
    Your choice. The `` runs during view build time. The `` runs during view render time. If you have view scoped beans and are using Mojarra older than 2.1.18, then `` breaks view scoped beans if the property behind `rendered` attribute references a view scoped bean property. – BalusC Jul 04 '13 at 15:19
  • Since I can control the environment, I have upgraded to Mojarra-2.1.22 and am now using `` in the tagfile. Thanks for the answer! – mabi Jul 04 '13 at 15:21