我可以让JSF2跳过呈现我的自定义标签而不修改标签本身吗? [英] Can I make JSF2 skip rendering my custom tag without modifying the tag itself?
问题描述
我已经使用 BalusC的模板开始了我自己的自定义标记处理程序(纯XHTML,没有Renderer),我们称之为bean:input
-典型的标签,输入,消息三重奏.它是这样使用的:
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>
麻烦的是,输入是互斥的(即,应仅显示其中之一).显示的是哪个输入是在渲染时由view参数确定的.我该怎么做?
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?
我不能使用<ui:fragment>
,因为这会弄乱panelGrid
,在标签上指定rendered="false"
无效,我有点犹豫将标签实现包装在大的<c:if test="#{rendered}">
中-是否在那里更好/内置的方法来告诉JSF,它应该只跳过呈现此特定标记?
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?
注意:当我通过部分更新重新渲染网格时,<c:if>
标记会做一些有趣的事情(例如,渲染不应渲染的标签,而不是相应的输入框).将rendered
属性添加到组件本身即可解决此问题.
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.
推荐答案
在标签文件中添加对rendered
属性的支持,然后将其重新应用于标签文件的内容.
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="..." />
我有点犹豫是否将标签实现包装在大型
<c:if test="#{rendered}">
这可能很难看,但是是的.
It's maybe ugly, but yes that's a way.
这篇关于我可以让JSF2跳过呈现我的自定义标签而不修改标签本身吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!