JSF 中的条件变量定义
我想根据条件更改变量值 所以我尝试了以下操作:
<h:head>
<ui:param name="userCase" value="Insert" />
<ui:fragment rendered="#{employee.employeesBulkInsert==false}">
<ui:param name="userCase" value="Update" />
</ui:fragment>
<title>#{userCase} Employee </title>
</h:head>
但它在更新情况下不起作用,它显示一个空字符串,有什么想法吗?
我知道还有其他解决方案,例如在支持 bean 中定义变量,或者直接在标题标签上制作条件 ui 片段,但我想知道为什么上述方法不起作用,请告知,谢谢。
i want to change the variable value based on a condition
so i tried the following:
<h:head>
<ui:param name="userCase" value="Insert" />
<ui:fragment rendered="#{employee.employeesBulkInsert==false}">
<ui:param name="userCase" value="Update" />
</ui:fragment>
<title>#{userCase} Employee </title>
</h:head>
but it doesn't work in the update case, it shows an empty string, any ideas why ?
i know that there are other solutions like defining the variable in the backing bean, or make the conditional ui fragment on the title tag directly, but i want to know why the above is not working, please advise, thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是渲染时标记,而
是标记处理程序(标记处理程序由于缺少渲染
属性)。因此,当构建视图时,无论
的结果如何,
都会被设置。
的rendered
属性仅在渲染已构建的视图时进行评估。您希望使用标记处理程序来创建条件,例如 JSTL
。(请注意,我删除了不必要的布尔
==false
比较)The
<ui:fragment>
is a render-time tag while the<ui:param>
is a tag handler (tag handlers are easily recognizeable by the absence of therendered
attribute). So when the view get built, the<ui:param>
is set, regardless of the outcome of<ui:fragment>
. Therendered
attribute of<ui:fragment>
is only evaluated when the already-built view is to be rendered.You want to make the condition using a tag handler instead, such as JSTL
<c:if>
.(note that I removed the unnecessary boolean
==false
comparison)尝试使用 JSTL 代替:
教程:http://www.ibm .com/developerworks/java/library/j-jstl0211/index.html
Try using JSTL instead:
Tutorial here: http://www.ibm.com/developerworks/java/library/j-jstl0211/index.html