JSF 中的条件变量定义

发布于 2024-12-19 13:27:19 字数 479 浏览 0 评论 0原文

我想根据条件更改变量值 所以我尝试了以下操作:

<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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

乱了心跳 2024-12-26 13:27:19

是渲染时标记,而 是标记处理程序(标记处理程序由于缺少渲染属性)。因此,当构建视图时,无论 的结果如何, 都会被设置。 rendered 属性仅在渲染已构建的视图时进行评估。

您希望使用标记处理程序来创建条件,例如 JSTL

<ui:param name="userCase" value="Insert" />

<c:if test="#{not employee.employeesBulkInsert}">
    <ui:param name="userCase" value="Update" />
</c:if>

(请注意,我删除了不必要的布尔 ==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 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.

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>

(note that I removed the unnecessary boolean ==false comparison)

∞梦里开花 2024-12-26 13:27:19

尝试使用 JSTL 代替:

<c:set var="userCase" value="Insert" />
<c:if test="#{employee.employeesBulkInsert}">
    <c:set var="userCase" value="Update" />
</c:if>

教程:http://www.ibm .com/developerworks/java/library/j-jstl0211/index.html

Try using JSTL instead:

<c:set var="userCase" value="Insert" />
<c:if test="#{employee.employeesBulkInsert}">
    <c:set var="userCase" value="Update" />
</c:if>

Tutorial here: http://www.ibm.com/developerworks/java/library/j-jstl0211/index.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文