9 Replies Latest reply on Feb 13, 2012 1:15 PM by sunkaram

    Problem with render and rendered

    adsonvinicius

      Hi,

      I have a rich:select populated dynamically. I'd like when an user change it, will render (or not)  a graphicImage depending of the selected value. How to do it?

       

                         <rich:select value="#{car.id}">

                             <f:selectItems value="#{carsMB.items}" />

                             <a4j:ajax event="change" render="image1" listener="" execute="@this"/>

                         </rich:select>

                          <h:graphicImage id="image1" value="/images/add.gif" alt=Add" />

       

       

      I think i need to put the function in listener  attributes, but what exactly?

        • 1. Re: Problem with render and rendered
          sunkaram

          try this:

                            

          <rich:select value="#{car.id}">

                                 <f:selectItems value="#{carsMB.items}" />

                                 <a4j:ajax event="change" render="image1" listener="actionbean.setImageName" execute="@this"/>

                             </rich:select>

                              <h:graphicImage id="image1" value="/images/#{actionbean.imageName}" alt=Add" />

           

          In the bean:

           

          String imageName = null;

          public void setImageName(AjaxBehaviorEvent event) {

               //get value from list box

               //based on list box value set image name  example "add.gif" or "edit.gif"

          }

           

          or you can also do this with

           

                               <rich:select value="#{car.id}">

                                 <f:selectItems value="#{carsMB.items}" />

                                 <a4j:ajax event="change" render="imageGroup"  execute="@this"/>

                             </rich:select>

                              <h:panelGroup id="imageGroup>

                                   <h:graphicImage id="image1" value="/images/add.gif" alt=Add" rendered="#{car.id == 1}"/>

                                   <h:graphicImage id="image2" value="/images/edit.gif" alt=Edit" rendered="#{car.id == 2}"/>

                                   <h:graphicImage id="image3" value="/images/save.gif" alt=Save" rendered="#{car.id == 3}"/>

                              </h:panelgroup>

          • 2. Re: Problem with render and rendered
            adsonvinicius

            Hi dude, i tried to do what you suggest and it works, the problem is because won't update until click on any place of the browser...

             

            <h:form>

                        <rich:panel style="width:320px; margin-top:15%; margin-left:40%;">

                          <f:facet name="header">

                             <h:outputText value="Praças:"></h:outputText>

                          </f:facet>

                            <h:panelGrid columns="4">

                                <rich:select id="selectGroup" value="#{projetoMB.id_praca}" defaultLabel="Selecione" required="true" requiredMessage="Requerido!">

                                   <f:selectItems value="#{projetoMB.pracas}" />

                                   <a4j:ajax event="change" render="imageGroup" execute="@this"/>

                               </rich:select>

                                <h:panelGroup id="imageGroup">

                                    <h:graphicImage id="image1" value="/images/delete.gif" alt="Remover" rendered="#{projetoMB.id_praca == 1}"/>

                                    <h:graphicImage id="image2" value="/images/edit.gif" alt="Editar" rendered="#{projetoMB.id_praca == 2}"/>

                                    <h:graphicImage id="image3" value="/images/new.gif" alt="Novo"/>

                                </h:panelGroup>

                            </h:panelGrid>

                            <div style="margin-top: 5px;" align="center">

                              <h:commandButton action="#{projetoMB.acessarProjeto}" value="Acessar"></h:commandButton>

                            </div>

                      </rich:panel>       

                   </h:form>

             

            Do you know why this happend?

            • 3. Re: Problem with render and rendered
              sunkaram

              you mean, it requires a click on the browser once you change the list box value?

               

              If you are trying it on IE, try it in another browser - firefox. sometimes there are browser specific issues with RF, which we need to handle with some tricks..

               

              Let me know...

              • 4. Re: Problem with render and rendered
                adsonvinicius

                Yes, exaclty that. I'm using google Chrome

                 

                Adson

                • 5. Re: Problem with render and rendered
                  sunkaram

                  I see people complaining about this problem in IE, but not in Chrome.. Do you have any other 'forms' in the page?  or this is the complete code in ur page?

                  • 6. Re: Problem with render and rendered
                    adsonvinicius

                    I Let me show you my complete page:

                     

                    <?xml version='1.0' encoding='UTF-8' ?>

                    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

                    <html xmlns="http://www.w3.org/1999/xhtml"

                        xmlns:h="http://java.sun.com/jsf/html"

                        xmlns:f="http://java.sun.com/jsf/core"

                        xmlns:ui="http://java.sun.com/jsf/facelets"

                        xmlns:a4j="http://richfaces.org/a4j"

                        xmlns:rich="http://richfaces.org/rich">

                        <h:outputStylesheet>

                           .panel{

                              width:400px;

                            }    

                           .centerLogin{

                              margin-top:15%;

                           }

                        </h:outputStylesheet>

                        <h:head>

                            <title>.: CMS - AEROPORTO :.</title>

                        </h:head>

                           <h:form>

                                <rich:panel style="width:320px; margin-top:15%; margin-left:40%;">

                                  <f:facet name="header">

                                     <h:outputText value="Praças:"></h:outputText>

                                  </f:facet>

                                    <h:panelGrid columns="4">

                                        <rich:select id="selectGroup" value="#{projetoMB.id_praca}" defaultLabel="Selecione" required="true" requiredMessage="Requerido!">

                                           <f:selectItems value="#{projetoMB.pracas}" />

                                           <a4j:ajax event="change" render="imageGroup" execute="@this"/>

                                       </rich:select>

                                        <h:panelGroup id="imageGroup">

                                            <h:graphicImage id="image1" value="/images/delete.gif" alt="Remover" rendered="#{projetoMB.id_praca == 1}"/>

                                            <h:graphicImage id="image2" value="/images/edit.gif" alt="Editar" rendered="#{projetoMB.id_praca == 2}"/>

                                            <h:graphicImage id="image3" value="/images/new.gif" alt="Novo"/>

                                        </h:panelGroup>

                                    </h:panelGrid>

                                    <div style="margin-top: 5px;" align="center">

                                      <h:commandButton action="#{projetoMB.acessarProjeto}" value="Acessar"></h:commandButton>

                                    </div>

                              </rich:panel>       

                           </h:form>

                        <rich:popupPanel id="deletePanel" autosized="true">

                            Tem certeza que deseja remover esta Praça?

                            <a4j:commandButton value="Cancelar" onclick="#{rich:component('deletePanel')}.hide(); return false;" />

                            <a4j:commandButton value="Remover" onclick="remove(); return false;" />

                        </rich:popupPanel>       

                       

                        <rich:popupPanel modal="true" id="addPanel" moveable="false" autosized="true">

                            <f:facet name="header"><h:outputText value="Adicionar Praça" /></f:facet>

                            <h:form>

                                <h:panelGrid id="addGrid" columns="1">

                                    <a4j:outputPanel id="pop1" ajaxRendered="false">

                                        <h:panelGrid columns="2">

                                            <h:outputText value="Nome" />

                                            <h:inputText value="#{projetoMB.novaPraca}" required="true" requiredMessage="Insira um nome!" />

                                        </h:panelGrid>

                                    </a4j:outputPanel>

                                </h:panelGrid>

                                <a4j:commandButton value="Salvar" action="{}" render="table" execute="addPanel" oncomplete="if (#{facesContext.maximumSeverity==null}) #{rich:component('addPanel')}.hide();" />

                                <a4j:commandButton value="Cancelar" onclick="#{rich:component('addPanel')}.hide(); return false;" /> 

                            </h:form>

                         </rich:popupPanel>   

                       

                        <rich:popupPanel modal="true" id="editPanel" moveable="false" autosized="true">

                            <f:facet name="header"><h:outputText value="Editar Praça" /></f:facet>

                            <h:form>

                                <h:panelGrid id="editGrid" columns="1">

                                    <a4j:outputPanel id="pop2" ajaxRendered="false">

                                        <h:panelGrid columns="2">

                                            <h:outputText value="Nome" />

                                            <h:inputText value="#{projetoMB.novaPraca}" required="true" requiredMessage="Insira um nome!" />

                                        </h:panelGrid>

                                    </a4j:outputPanel>

                                </h:panelGrid>

                                <a4j:commandButton value="Salvar" action="{}" render="table" execute="editPanel" oncomplete="if (#{facesContext.maximumSeverity==null}) #{rich:component('editPanel')}.hide();" />

                                <a4j:commandButton value="Cancelar" onclick="#{rich:component('editPanel')}.hide(); return false;" /> 

                            </h:form>

                         </rich:popupPanel>

                    </html>

                    • 7. Re: Problem with render and rendered
                      sunkaram

                      I am not seeing any problem with your code..

                       

                      just try following things:

                       

                      use <f:selectOneMenu> in place of <rich:select for list list box

                       

                      or

                       

                      use event="selectitem" incase of event="change"

                      • 8. Re: Problem with render and rendered
                        adsonvinicius

                        It works, thank you very much Sunkara, btw do you know why it happens?

                        • 9. Re: Problem with render and rendered
                          sunkaram

                          no idea.. will post back in case I find out...

                           

                          Anyway, glad to hear that its working...