Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

jsf

jstl

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?

like image 996
Koekiebox Avatar asked Sep 15 '11 21:09

Koekiebox


1 Answers

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:

  • Conditionally displaying JSF components
like image 122
BalusC Avatar answered Sep 30 '22 02:09

BalusC