问题
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.
回答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.
来源:https://stackoverflow.com/questions/17473377/can-i-make-jsf2-skip-rendering-my-custom-tag-without-modifying-the-tag-itself