JSF中的条件变量定义 [英] Conditional variable definition in JSF
问题描述
我想根据条件更改变量值 所以我尝试了以下方法:
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 ?
我知道还有其他解决方案,例如在backing bean中定义变量,或者直接在title标签上创建条件ui片段,但是我想知道为什么上面的方法不起作用,请告知,谢谢.
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.
推荐答案
<ui:fragment>
是渲染时标记,而<ui:param>
是标记处理程序(通过缺少rendered
可以轻松识别标记处理程序属性).因此,在构建视图时,无论<ui:fragment>
的结果如何,都将设置<ui:param>
. <ui:fragment>
的rendered
属性仅在将呈现已构建的视图时评估.
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 the rendered
attribute). So when the view get built, the <ui:param>
is set, regardless of the outcome of <ui:fragment>
. The rendered
attribute of <ui:fragment>
is only evaluated when the already-built view is to be rendered.
您想改为使用标记处理程序来创建条件,例如JSTL <c:if>
.
You want to make the condition using a tag handler instead, such as JSTL <c:if>
.
<ui:param name="userCase" value="Insert" />
<c:if test="#{not employee.employeesBulkInsert}">
<ui:param name="userCase" value="Update" />
</c:if>
(请注意,我删除了不必要的布尔==false
比较)
这篇关于JSF中的条件变量定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!