9 Replies Latest reply on Mar 18, 2010 2:19 PM by lenyas66

    Using expressions in rendered (or any other boolean attribute)

    lenyas66

      I have a command button, which I want to  be rendered, if 2 conditions are satisified.

       

      Somehow, if I use "&&" in the expression it throws the usual exception:

       

      The entity name must immediately follow the ‘&’ in the entity reference

       

      If I replace "&&" with " &&" though, condition doesn't seem to be working.

       

      Here's the code:

       

       

      <a4j:commandButton id="expRetExcel" value="Download Returns"

       

      styleClass="command-button" rendered="#{renderPeriodicity && qtBeanParam.trailingVisible}"

      action="#{qtBeanParam.genReturnsWorkBook}" immediate="false"

       

      oncomplete="showResults(#{qtBeanParam.retRandNum}, #{qtBeanParam.hasExcelData})">

       

      </a4j:commandButton>

       

      Note, that first parameter (renderPeriodicity) is "ui:param", but second comes from the bean:

       

      <

       

      ui:param name="renderPeriodicity" value="false"/>

       

      ...

       

      private

       

       

      boolean trailingVisible = true;

       

      Am I doing something wrong here?

        • 1. Re: Using expressions in rendered (or any other boolean attribute)
          harut

          You should use "and"

          rendered="#{renderPeriodicity and qtBeanParam.trailingVisible}"

          • 2. Re: Using expressions in rendered (or any other boolean attribute)
            lenyas66

            That doesn't work. here's the code snippet:

             

            <

             

            a4j:commandButton id="expRetExcel" value="Download Returns"

             

            styleClass="command-button" rendered="#{renderPeriodicity and qtBeanParam.trailingVisible}"

             

            action="#{qtBeanParam.genReturnsWorkBook}" immediate="false"

             

            oncomplete="showResults(#{qtBeanParam.retRandNum}, #{qtBeanParam.hasExcelData})">

             

            </a4j:commandButton>

             

            Trailing visible gets set, when radio button value "trailing" is selected. Button is still visible, even when selectOneRadio has non-trailing value.

             

            <

             

            h:selectOneRadio id="periodType" value="#{qtBeanParam.curTimePeriod.periodType}" immediate="true"

             

            required="true" valueChangeListener="#{qtBeanParam.periodTypeChange}">

             

            <a4j:support event="onclick" reRender="sortingPanel,timePanel,expRetExcel" ajaxSingle="true" />

             

            <f:selectItem id="itemT" itemLabel="Trailing" itemValue="TRAILING" />

             

            <f:selectItem id="itemC" itemLabel="Calendar" itemValue="CALENDAR" />

             

            <f:selectItem id="itemCus" itemLabel="Custom" itemValue="CUSTOM" />

             

            </h:selectOneRadio>

             

            ...

             

            public

             

             

            void periodTypeChange(ValueChangeEvent vce) {

             

            logger.debug("<changeBenchmark>" + vce.getNewValue());

             

            PhaseId phaseId = vce.getPhaseId();

             

            final PeriodType pt = (PeriodType)vce.getNewValue();

             

             

            if ( phaseId.equals(PhaseId.ANY_PHASE))

            {

            vce.setPhaseId(PhaseId.

            UPDATE_MODEL_VALUES);

            vce.queue();

            }

             

            else if ( phaseId.equals(PhaseId.UPDATE_MODEL_VALUES))

            {

             

            if (PeriodType.TRAILING == pt) {

             

            trailingVisible = true;

             

            calendarVisible = false;

             

            customVisible = false;

             

            allowSorting = true;

            }

             

            if(PeriodType.CALENDAR == pt) {

             

            calendarVisible = true;

             

            trailingVisible = false;

             

            customVisible = false;

             

            allowSorting = false;

             

            //prevent any trailing periods from being processed

            }

             

            if(PeriodType.CUSTOM == pt) {

             

            calendarVisible = false;

             

            trailingVisible = false;

             

            customVisible = true;

             

            allowSorting = false;

             

            //prevent any trailing periods from being processed

            }

            }

             

            • 3. Re: Using expressions in rendered (or any other boolean attribute)
              ufonaut

              If a string literal is not empty, it'll evaluate as true.

               

              try :

              ui:param name="renderPeriodicity" value="#{false}"/>

              • 4. Re: Using expressions in rendered (or any other boolean attribute)
                harut

                That doesn't work. here's the code snippet:

                 

                "and" is the correct EL expression, and you can't get your expected result because of another reson.

                 

                 

                 

                <h:selectOneRadio id="periodType" value="#{qtBeanParam.curTimePeriod.periodType}" immediate="true"

                 

                required="true" valueChangeListener="#{qtBeanParam.periodTypeChange}">

                 

                <a4j:support event="onclick" reRender="sortingPanel,timePanel,expRetExcel" ajaxSingle="true" />

                 

                <f:selectItem id="itemT" itemLabel="Trailing" itemValue="TRAILING" />

                 

                <f:selectItem id="itemC" itemLabel="Calendar" itemValue="CALENDAR" />

                 

                <f:selectItem id="itemCus" itemLabel="Custom" itemValue="CUSTOM" />

                 

                </h:selectOneRadio>


                You are reRendering "expRetExcel" and that is the reason that the button still visible after non-trailing value. You should reRender another top level component which contains that commandButton -- e.g.

                 

                <h:panelGroup id="buttonsArea">

                    <a4j:commandButton id="expRetExcel" value="Download Returns"

                 

                     styleClass="command-button" rendered="#{renderPeriodicity and qtBeanParam.trailingVisible}"

                 

                     action="#{qtBeanParam.genReturnsWorkBook}" immediate="false"

                 

                     oncomplete="showResults(#{qtBeanParam.retRandNum}, #{qtBeanParam.hasExcelData})">

                 

                     </a4j:commandButton>

                </h:panelGroup>

                 

                and reRender "buttonsArea" in a4j:support. After that the button will become invisible...

                1 of 1 people found this helpful
                • 5. Re: Using expressions in rendered (or any other boolean attribute)
                  ilya_shaikovsky

                  yes. that should be the reason..

                   

                  B.t.w. Harut, thanks for your efforts! Just for clarification we could not insert DOM element via ajax and should update the parents.. but removal should still work in his case althought it's still not preferable way for sure

                  • 6. Re: Using expressions in rendered (or any other boolean attribute)
                    harut

                    Hi Ilya, Glad to help in something!

                    Just for clarification we could not insert DOM element via ajax and should update the parents.. but removal should still work in his case althought it's still not preferable way for sure

                     

                    I see... I had a same strange behavior as Leonid's case a year ago, and after finding a solution, all reRenders (for rendering some components) I am making on top level ones intuitively... so it becomes 'preferable' way for me

                    • 7. Re: Using expressions in rendered (or any other boolean attribute)
                      lenyas66

                      Getting there, but not there yet :-)

                       

                      I made the changes as suggested, but it is still rendered when trailingVisible is false. Any other ideas?

                       

                      <

                       

                      h:selectOneRadio id="periodType" value="#{qtBeanParam.curTimePeriod.periodType}" immediate="true"

                       

                      required="true" valueChangeListener="#{qtBeanParam.periodTypeChange}">

                       

                      <a4j:support event="onclick" reRender="sortingPanel,timePanel,exportReturns" ajaxSingle="true" />

                       

                      <f:selectItem id="itemT" itemLabel="Trailing" itemValue="TRAILING" />

                       

                      <f:selectItem id="itemC" itemLabel="Calendar" itemValue="CALENDAR" />

                       

                      <f:selectItem id="itemCus" itemLabel="Custom" itemValue="CUSTOM" />

                       

                      </h:selectOneRadio>

                      ...

                       

                      <

                       

                      h:panelGroup id="exportReturns" rendered="#{qtBeanParam.trailingVisible}">

                       

                      <a4j:commandButton id="expRetExcel" value="Download Returns"

                       

                      styleClass="command-button" rendered="#{renderPeriodicity}"

                       

                      action="#{qtBeanParam.genReturnsWorkBook}" immediate="false"

                       

                      oncomplete="showResults(#{qtBeanParam.retRandNum}, #{qtBeanParam.hasExcelData})">

                       

                      </a4j:commandButton>

                       

                      </h:panelGroup>

                      • 9. Re: Using expressions in rendered (or any other boolean attribute)
                        lenyas66

                        This has worked!

                         

                        Thanks a lot, Nick and everybody else for your valuable input.

                         

                        Final version looks as follows:

                         

                        <

                         

                        a4j:outputPanel id="exportReturns" >

                         

                        <a4j:commandButton id="expRetExcel" value="Download Returns"

                         

                        styleClass="command-button" rendered="#{renderPeriodicity and qtBeanParam.trailingVisible}"

                         

                        action="#{qtBeanParam.genReturnsWorkBook}" immediate="false"

                         

                        oncomplete="showResults(#{qtBeanParam.retRandNum}, #{qtBeanParam.hasExcelData})">

                         

                        </a4j:commandButton>

                         

                        </a4j:outputPanel>