开发者

<c:choose> not working in datatable

开发者 https://www.devze.com 2023-02-23 06:31 出处:网络
In a datatable开发者_运维技巧 a value needs to be translated when a certain condition applies (link enabled):

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?


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 as var of the datatable. At the moment JSTL runs, this variable is not available, so it's always null at that point.

You need to use JSF tags/attributes instead. In this particular case you want to use the JSF rendered attribute instead.

<h:outputText value="#{pluginSummary.pluginid}" rendered="#{not pluginSummary.linkEnabled}" />
<h:outputText value="#{texts[pluginSummary.pluginid]}" rendered="#{pluginSummary.linkEnabled}"/>

(note that I also changed the method invocation to a property since that's clearer since you don't need to pass any arguments)


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号