不在数据表中工作
在数据表中,当某个条件适用(启用链接)时,需要转换值:
<h:outputLink disabled="#{pluginSummary.linkEnabled}" target="_blank" value="http://www.nessus.org/plugins/index.php">
<c:choose>
<c:when test="#{not pluginSummary.isLinkEnabled()}" >
<h:outputText value="#{pluginSummary.pluginid}"/>
</c:when>
<c:otherwise>
<h:outputText value="#{texts[pluginSummary.pluginid]}"/>
</c:otherwise>
</c:choose>
<f:param name="id" value="#{pluginSummary.pluginid}"/>
<f:param name="view" value="single"/>
</h:outputLink>
但奇怪的是,只有第一个条件适用,并且永远不会进行转换。为了调试,我还添加了
如果 c:choose 在数据表中有效,我有什么选择?
In a datatable a value needs to be translated when a certain condition applies (link enabled):
<h:outputLink disabled="#{pluginSummary.linkEnabled}" target="_blank" value="http://www.nessus.org/plugins/index.php">
<c:choose>
<c:when test="#{not pluginSummary.isLinkEnabled()}" >
<h:outputText value="#{pluginSummary.pluginid}"/>
</c:when>
<c:otherwise>
<h:outputText value="#{texts[pluginSummary.pluginid]}"/>
</c:otherwise>
</c:choose>
<f:param name="id" value="#{pluginSummary.pluginid}"/>
<f:param name="view" value="single"/>
</h:outputLink>
But strangely only the first condition applies and there is never a translation. To debug I also added a <h:outputText value="#{pluginSummary.isLinkEnabled()}/>
and there I see the different true and false entries, but I the text gets never translated.
Does anybody know, if c:choose works in a datatable? What are my alternatives?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
JSTL 标记和 JSF 标记并不像您期望的编码那样同步运行。 JSTL 标记在视图构建时运行,JSF 标记在视图渲染时运行。您可以将其形象化如下:JSTL 首先从上到下运行,然后将生成的结果(没有任何 JSTL 标签!)交给 JSF,JSF 又从上到下运行,为 Web 浏览器生成 HTML。
我知道
#{pluginSummary}
被定义为数据表的var
。在 JSTL 运行时,该变量不可用,因此此时它始终为null
。您需要改用 JSF 标签/属性。在这种特殊情况下,您希望改用 JSF
rendered
属性。(请注意,我还将方法调用更改为属性,因为这样更清楚,因为您不需要传递任何参数)
JSTL tags and JSF tags doesn't run in sync as you'd expect from coding. JSTL tags runs during view build time and JSF tags runs during view render time. You can visualize it as follows: JSTL runs from top to bottom first and then hands over the generated result (without any JSTL tags!) to JSF which in turn runs from top to bottom again to produce HTML for the webbrowser.
I understand that
#{pluginSummary}
is definied asvar
of the datatable. At the moment JSTL runs, this variable is not available, so it's alwaysnull
at that point.You need to use JSF tags/attributes instead. In this particular case you want to use the JSF
rendered
attribute instead.(note that I also changed the method invocation to a property since that's clearer since you don't need to pass any arguments)
一种是jstl标签,另一种是jsf组件。他们有不同的评估时间。
您应该使用组件的
rendered
属性来有条件地渲染它们。One is jstl tag, the others are jsf components. They have different evaluation times.
You should use the
rendered
attribute of components to render them conditionally.