h:outputText有条件地渲染不再在JSF 2中工作的JSF元素组? [英] h:outputText to conditionally render groups of JSF elements no longer working in JSF 2?
问题描述
我有一些使用< h:outputText>
的代码有条件地呈现JSF元素组.例子:
I have some code that uses <h:outputText>
to conditionally render groups of JSF elements. Examples:
<h:outputText rendered="#{authorization.admin}">
<h:outputText value="#{msgs.someinfo}" />
<h:inputSecret value="#{usermanager.password}" />
</h:outputText>
<h:outputText rendered="#{contactmanager.editAction}">
<li>
<label for="name"><h:outputText value="#{msgs.nameinfo}" /></label>
<h:inputText id="name" value="#{contactmanager.name}" />
<h:messages for="name" />
</li>
</h:outputText>
代码在glassfish 2.1.1上,该文件在jsf-impl.jar中具有MANIFEST.MF,如下所示(我不确定它是否实际上在JSF中使用此jar或其他jar):
The code is on glassfish 2.1.1 which has the MANIFEST.MF in jsf-impl.jar looking like this (I'm not sure whether it actually uses this jar or some other one for JSF):
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.7.0
Created-By: 1.5.0_19-b02 (Sun Microsystems Inc.)
Specification-Title: JavaServer Faces
Specification-Version: 1.2MR2
Implementation-Title: Mojarra
Implementation-Version: 1.2_13-b01-FCS
Implementation-Vendor: Sun Microsystems, Inc.
Implementation-Vendor-Id: com.sun
Extension-Name: com.sun.faces
我正在尝试使用具有某些JSF 2或更高版本的glassfish 4.
I'm trying to move to glassfish 4 which has some version of JSF 2 or higher.
此构造的所有数百个实例都在旧的glassfish上运行,但是它们不再在新的glassfish上运行-不管 rendered
属性的计算结果如何,它们都将被替换为空.为什么?
All the hundreds of instances of this construct worked on the old glassfish, but they no longer work on the new one - they are replaced with nothing, regardless of what the rendered
attribute evaluates to. Why?
推荐答案
实际上,由于JSF 2.0,默认不再渲染 UIInput
和 UIOutput
的子级.这是对问题1154 进行修复的结果.在Mojarra 2.x中,您仍然可以通过 web.xml
上下文参数将其重新打开:
Indeed, since JSF 2.0, children of UIInput
and UIOutput
are by default not anymore rendered. This is the consequence of fixes for issue 1154. In Mojarra 2.x, you can still turn it back on via a web.xml
context parameter:
<context-param>
<param-name>com.sun.faces.allowTextChildren</param-name>
<param-name>true</param-name>
</context-param>
另请参见 Mojarra 2.0.0发行说明.
但是,更建议改为使用< h:panelGroup>
或< ui:fragment>
来有条件地将块表示为< h:outputText>
只是错误的工具和贸易;为了工作.
It's however more recommended to instead use <h:panelGroup>
or <ui:fragment>
for conditional rendering of blocks as the <h:outputText>
is just the Wrong Tool™ for the job.
这篇关于h:outputText有条件地渲染不再在JSF 2中工作的JSF元素组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!