Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
212 views
in Technique[技术] by (71.8m points)

java - JSTL c:choose c:when not working in a JSF page

Consider the following jstl choose:

<c:choose>
    <c:when test="#{AuthMsgBean.rw['2'] ne null}">
        Display Text
    </c:when>

    <c:otherwise>
        <ph:outputText id="pan" value="Component pan could not be created." />
    </c:otherwise>
</c:choose>

AuthMsgBean = Bean

rw = Map

'2' = Key


Question:

When I simply display the #{AuthMsgBean.rw['2'] ne null} value it displays fine (true), but once I try to parse the value to the <c:when test=""/> the when tag re-acts as if the test is always false.

If I put true in the test (test="true") the Display Text is displayed.

Could it be that the <c:when> tag is evaluated before the #{AuthMsgBean.rw['2'] ne null} expression?

If so, is there a workaround?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

JSTL and JSF do not run in sync as you'd expect from coding. During JSF view build time, it's JSTL which runs from top to bottom first to produce a view with only JSF tags. During JSF view render time, it's JSF which runs from top to bottom again to produce a bunch of HTML.

Apparently the #{AuthMsgBean} is not present in the scope when it's JSTL's turn to run. That can happen when the tags are placed inside a JSF iterating component such as <h:dataTable>.

Regardless, you do not want to use JSTL here. Make use of the JSF rendered attribtue.

<h:panelGroup rendered="#{not empty AuthMsgBean.rw['2']}">
    Display Text
</h:panelGroup>
<h:outputText id="pan" value="Component pan could not be created." rendered="#{empty AuthMsgBean.rw['2']}" />

See also:


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...