我想有条件地输出一些Facelets代码.
为此,JSTL标签似乎工作正常:
<c:if test="${lpc.verbose}">
...
</c:if>
Run Code Online (Sandbox Code Playgroud)
但是,我不确定这是否是最佳做法?还有另一种方法来实现我的目标吗?
是否可以在EL表达式中定义变量并重新使用该变量?
例如 :
<h:inputText
value="#{myBean.data.something.very.long}"
rendered="#{myBean.data.something.very.long.showing}"
/>
Run Code Online (Sandbox Code Playgroud)
我的想法是这样的:
<!--
somehow define a variable here like :
myVar = #{myBean.data.something.very.long}
-->
<h:inputText
value="#{myVar}"
rendered="#{myVar.showing}"
/>
Run Code Online (Sandbox Code Playgroud)
有任何想法吗 ?谢谢 !
我的表单上有if-else条件,我在其中显示标题和按钮文本以进行添加和更新.
下面我在struts2项目中使用的代码和相同的代码想在xhtml页面的JSF2项目中使用.
Struts2
<s:if test="person==null || person.id==null || person.id==''">
<s:set var="buttonText" value="getText('person.button.add')"/>
<s:text name="person.h1.add.text"/>
<i><s:text name="person.smallfont.add.text"/></i>
</s:if>
<s:else>
<s:set var="buttonText" value="getText('person.button.edit')"/>
<s:text name="person.h1.edit.text"/>
<s:text name="person.smallfont.edit.text"/>
</s:else>
Run Code Online (Sandbox Code Playgroud)
我可以在xhtml页面中使用JSTL并使用上面的代码,但我在下面使用EL看到了不同的方法.我不确定,但不喜欢下面的方法
<h:outputLabel value="Add Information" rendered="#{!empty personBean.person.id}" />
<h:outputLabel value="Use the form below to add your information." rendered="#{!empty personBean.person.id}" />
<h:outputLabel value="Update Information" rendered="#{empty personBean.person.id}" />
<h:outputLabel value="Use the form below to edit your information." rendered="#{empty personBean.person.id}" />
Run Code Online (Sandbox Code Playgroud)
我的问题:
有人指导我如何在JSF项目的IF-ELSE条件中使用上面的代码.使用EL/JSTL还是其他?