3

for example: when I click on the button A. I get the following text : you have choosed A.

But when I change button, I get the same text, although the value of #{bean.str} changes

Here is my code :

<p:selectOneButton id="selectId" value="#{bean.str}">
            <f:selectItem itemLabel="A" itemValue="1" />
            <f:selectItem itemLabel="B" itemValue="2" />
            <f:selectItem itemLabel="C" itemValue="3" />
            <f:ajax event="change" render="tabView" listener="#{bean.change}" />
</p:selectOneButton>

<c:if var="test" test="#{bean.str =='1'}">
        <h:outputText value="you have choosed A" />
</c:if>
<c:if test="#{beanApplication.perspective=='2'}">
        <h:outputText value="you have choosed B" />
</c:if>
<c:if test="#{beanApplication.perspective=='3'}">
        <h:outputText value="you have choosed C" />
</c:if>

I am looking for a way to refresh the JSTL <c:if> test when I click on the button.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Karim Oukara
  • 2,638
  • 8
  • 38
  • 51
  • You forgot to obfuscate some `beanApplication.perspective` expressions, hereby introducing red herrings in your question. Please edit in the real code and test it and copypaste the real code (so, don't not edit in the question afterwards). – BalusC Nov 12 '12 at 14:28

3 Answers3

5

JSTL runs during JSF view build time, not during JSF view render time. However, the submitted value is in this particular example only set as bean property after view build time. The view build time runs during JSF RESTORE_VIEW phase, but the bean property is set during JSF UPDATE_MODEL_VALUES phase.

You need to evaluate the condition during render time instead. Use the therefor provided JSF component's rendered attribute.

<h:outputText value="you have chosen A" rendered="#{bean.str == '1'}" />
<h:outputText value="you have chosen B" rendered="#{bean.str == '2'}" />
<h:outputText value="you have chosen C" rendered="#{bean.str == '3'}" />

Further, you should be using <p:ajax> in PrimeFaces components, not <f:ajax>. Also you should ensure that the component referenced as tabView in <f:ajax render> (and equivalently, the <p:ajax update>) covers the above three components. Here's a complete kickoff example:

<p:selectOneButton id="selectId" value="#{bean.str}">
    <f:selectItem itemLabel="A" itemValue="1" />
    <f:selectItem itemLabel="B" itemValue="2" />
    <f:selectItem itemLabel="C" itemValue="3" />
    <p:ajax listener="#{bean.change}" update="tabView" />
</p:selectOneButton>

<h:panelGroup id="tabView">
    <h:outputText value="you have chosen A" rendered="#{bean.str == '1'}" />
    <h:outputText value="you have chosen B" rendered="#{bean.str == '2'}" />
    <h:outputText value="you have chosen C" rendered="#{bean.str == '3'}" />
</h:panelGroup>

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • thank you for you response my friend !. I tried your suggestion but I get the same result. now I tried to put all ` – Karim Oukara Nov 12 '12 at 14:35
  • 1
    You're welcome. The JSTL problem is indeed not immediately obvious to starters, but I'd expect that the mis-rendering problem would be obvious enough to starters (as this is clearly visible in ajax response). – BalusC Nov 12 '12 at 14:37
1

You can put all condition in a panel and re render on the button click

zaffargachal
  • 802
  • 7
  • 21
0

use the attribute "rendered" on your 3 outputText

willome
  • 3,062
  • 19
  • 32