0

In my problem, I have to display h:panelGroup based on a condition. For this h:panelGroup, the rendered attribute has already been set.

 <h:panelGroup rendered="#{not empty program.categories}">
    <li>
        <strong>Category: </strong> 
        <h:outputLabel value="#{not empty program.categories ? 'A':'N/A'}"/>
    </li>
 </h:panelGroup>

now I am trying to keep a condition like the code below:

<c:if test="${program.distTypeName != 'X' || program.distTypeName != 'Y' || program.distTypeName != 'Z'}">

<h:panelGroup rendered="#{not empty program.categories}">
    <li>
        <strong>Category: </strong> 
        <h:outputLabel value="#{not empty program.categories ? 'A':'N/A'}" />
    </li>
</h:panelGroup>

but this is not working. Please tell me what I am doing wrong. Basically, if the disType is not in x,y,z then I need to display the h:panelGroup.

How do we test not in condition with jstl tags? Thanks in advance.

Andy
  • 5,900
  • 2
  • 20
  • 29
sahithi
  • 25
  • 2
  • 7
  • 1
    This [link](http://stackoverflow.com/questions/4870462/conditionally-displaying-jsf-components/4870557#4870557) will help you. – danRod Jul 10 '13 at 19:59
  • but how can use rendered atrribute in my scenario.. is not working..i should check condition only for this h:panelGroup..not for the entire form. please suggest. – sahithi Jul 11 '13 at 02:37
  • Move the `` condition inside the `rendered` attribute of `` – Andy Jul 11 '13 at 06:49
  • Provided that `distTypeName` is an enum or a string, the code posted so far is perfectly legit when considered standalone (e.g. when that's the sole content of ``). Isn't that code *actually* inside an `` or `` or so? If so, then this question duplicates http://stackoverflow.com/questions/3442380/jstl-cif-inside-a-jsf-hdatatable Please take that into account in your future questions (the code posted so far should reproduce the problem when interpreted as the sole content of ``). See also http://stackoverflow.com/tags/jsf/info – BalusC Jul 11 '13 at 16:11

1 Answers1

0

JSTL tags and JSF tags are not synchronous. JSTL tags run in build time while JSF tags run in render time. That is why you see a strange behavior. You should use JSF rendered attribute instead of c:if

Furthermore, char comparison also works differently from Java. Chars behave like String in EL expressions which means != operator does not give proper results for String comparison.

<c:if test="${program.distTypeName != 'X' || program.distTypeName != 'Y' || program.distTypeName != 'Z'}">

Above c:if statement can be converted to rendered attribute like

<h:panelGroup rendered="#{program.distTypeName.compareTo('X') != 0 || program.distTypeName.compareTo('Y') != 0 || program.distTypeName.compareTo('Z') != 0}">

or ASCII representations of characters can also be used here if distTypeName is a char.

<h:panelGroup rendered="#{program.distTypeName ne 88 || program.distTypeName ne 89 || program.distTypeName ne 90}">

Related Post

https://stackoverflow.com/a/4154930/892994

Community
  • 1
  • 1
erencan
  • 3,725
  • 5
  • 32
  • 50
  • This is likely not the cause. The code as OP postes so far is perfectly legit. This would only cause problems if the code posted so far is actually inside a JSF repeater component such as `` or ``, but nothing in the question indicates that. The bean name `#{program}` is already a big hint that it represents an entity not a backing bean. – BalusC Jul 11 '13 at 16:11