在JSF2 xhtml页面中声明和使用变量 [英] Declare and use variable in JSF2 xhtml page

查看:101
本文介绍了在JSF2 xhtml页面中声明和使用变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在JSTL中使用<s:set var="buttonText" value="getText('person.button.add')"/>来使用buttonText变量设置文本.

I am using <s:set var="buttonText" value="getText('person.button.add')"/> in JSTL to use buttonText variable to set text.

有人告诉我如何在JSF EL中完成此操作吗?

此处提出的问题 JSF格式的IF-ELSE条件.需要知道正确的方法,但被告知作为一个单独的问题来回答.

Question asked here IF-ELSE condition in JSF form. Need to know right approach but told to ask as a separate question.

已编辑

我已经在上面添加了一个链接以获取详细信息,但是这里再次出现.

I already added a link above for detail but here is again.

我在struts2项目中使用的是JSTL

I am using JSTL like in struts2 project

 <s:if test="person==null || person.id==null || person.id==''">
                <s:set var="buttonText" value="getText('person.button.add')"/>
            </s:if>
            <s:else>
                <s:set var="buttonText" value="getText('person.button.edit')"/>
            </s:else>

我想在JSF2中使用相同的方法,但是要使用表达语言.我将值保存在名为buttonText的变量中,并在类似#{buttonText}的位置下面访问它.我需要如何在EL中编写变量并使用它的解决方案.希望它清除.

I want to use same approach in JSF2 but with Expression Language. I am saving value in a variable called buttonText and accessing it below somewhere like #{buttonText}. I need solution to how to write variable in EL and use it. Hope its clear.

我只需要解决<s:set var="buttonText" value="getText('person.button.add')"/>行代码.

谢谢

推荐答案

您可以使用ui:param

通过以下方式:

<ui:param name="buttonText" value="#{myBean.MyValue}" />

<ui:param name="buttonText" value="someText" />

<ui:param name="buttonText" value="someText#{myBean.MyValue}" />

,以后像这样使用

<h:outputText value="#{buttonText}"/>


另一种选择是通过以下方式使用<c:set

<c:set var="buttonText" value="#{myBean.MyValue}" />

但是请注意,<c:set是JSTL标记

But note that <c:set is a JSTL tag,

JSTL标记在构建视图期间运行(将XHTML文件转换为 JSF组件树)

JSTL tags runs during building the view (when the XHTML file is converted to JSF component tree)

您还可能想阅读JSF2 Facelets中的 JSTL ...有意义吗?

Also you might want to read this JSTL in JSF2 Facelets… makes sense?

这篇关于在JSF2 xhtml页面中声明和使用变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆