1 Reply Latest reply on Jun 15, 2011 6:16 PM by Noel Marín

    Execute valueChangeListener method after first request

    Noel Marín Newbie

      Hi everybody

       

      I'm currently having a weird error. I have two popup panels, the first one has two a4j:repeat, one for iterating tables, show the table name, and the other for iterating columns of the table:

       

                <rich:popupPanel id="asociacionCampoBDPopup" modal="true" width="710" height="480">

                      <f:facet name="header">

                          <h:outputText value="Asociar campo" />

                      </f:facet>               

                      <h:form id="bdform">

                          <h:panelGrid columns="1">

                              <a4j:outputPanel id="panel" layout="block">

                                  <a4j:repeat value="#{crearFuenteMB.tablasOriginales}" var="tablaVO" rows="20" id="tablasOriginales">

                                      <rich:panel style="float:left; width:200px; padding:5px; margin:5px">

                                          <f:facet name="header">

                                              <h:outputText value="#{tablaVO.tabla.nombre}" style="font-weight:bold" />

                                          </f:facet>

                                          <h:panelGrid columns="2">

                                              <a4j:repeat value="#{tablaVO.columnasTablaVO}" var="columnaVO" id="columnas">

                                                  <a4j:outputPanel layout="block">

                                                      <h:selectBooleanCheckbox id="check" value="#{columnaVO.seleccionada}" valueChangeListener="#{crearFuenteMB.mostrarFormAsociarColumnaBD}" immediate="true">                                                   

                                                          <a4j:ajax event="change" render="asociacionCampoBDFormPopup,javascriptCode" oncomplete="mostrarFormAsociarColumnaBD()" />

                                                          <f:attribute name="nombreColumna" value="#{columnaVO.columna.nombre}" />

                                                      </h:selectBooleanCheckbox>

                                                      <h:outputText value="#{columnaVO.columna.nombre}" />

                                                  </a4j:outputPanel>                                   

                                              </a4j:repeat>

                                          </h:panelGrid>

                                      </rich:panel>

                                  </a4j:repeat>

                              </a4j:outputPanel>

                              <a4j:outputPanel layout="block">

                                  <rich:dataScroller for="tablasOriginales" render="panel" />

                              </a4j:outputPanel>

                              <a4j:commandButton value="Cerrar" action="#{crearFuenteMB.cerrar}" onclick="#{rich:component('asociacionCampoBDPopup')}.hide(); return false;" immediate="true" />

                          </h:panelGrid>

                      </h:form>

                  </rich:popupPanel>

       

      By each column it shows a selectBooleanCheckbox and the name of the column, when the user selects the checkbox a valueChangeListener fires up and shows the other popupPanel:

       

                <rich:popupPanel id="asociacionCampoBDFormPopup" modal="true" width="420">

                      <f:facet name="header">

                          <h:outputText value="Asociar campo" />

                      </f:facet>

                      <h:form>

                          <h:panelGrid width="400" columns="2">

                              <h:outputLabel value="Columna(s) Seleccionada(s)" for="columnaSeleccionada" />

                                  <h:panelGroup layout="block">                   

                                      <h:inputText id="columnaSeleccionada" value="#{crearFuenteMB.columna.nombre}" required="true" requiredMessage="${msgs.mensaje_requerido}" readonly="true" />

                                      <h:message for="columnaSeleccionada" />

                                  </h:panelGroup>

                                 

                                  <h:outputLabel value="Valor predeterminado" for="vplvColumna" rendered="#{crearFuenteMB.campoListaValores}" />

                                      <h:panelGroup layout="block" rendered="#{crearFuenteMB.campoListaValores}">                   

                                          <h:selectOneListbox id="vplvColumna" value="#{crearFuenteMB.columna.valores.idValor}" size="1">

                                              <f:selectItems value="#{crearFuenteMB.valoresSI}"></f:selectItems>

                                          </h:selectOneListbox>

                                          <h:message for="vplvColumna" />

                                      </h:panelGroup>

                                     

                                      <h:outputLabel value="Valor predeterminado" for="vpColumna" rendered="#{crearFuenteMB.campoAbierto}" />

                                      <h:panelGroup layout="block" rendered="#{crearFuenteMB.campoAbierto}">                   

                                          <h:inputText id="vpColumna" value="#{crearFuenteMB.columna.valorTexto}" />

                                          <h:message for="vpColumna" />

                                      </h:panelGroup>

                                     

                                      <h:outputLabel value="Columna obligatoria" for="columnaObligatoria" />

                                      <h:panelGroup layout="block">                   

                                          <h:selectBooleanCheckbox id="columnaObligatoria" value="#{crearFuenteMB.columna.obligatorio}" />

                                          <h:message for="columnaObligatoria" />

                                      </h:panelGroup>

                                     

                                      <h:outputLabel value="Columna con información legitima" for="columnaLegitima" />

                                      <h:panelGroup layout="block">                   

                                          <h:selectBooleanCheckbox id="columnaLegitima" value="#{crearFuenteMB.columna.legitimidad}" />

                                          <h:message for="columnaLegitima" />

                                      </h:panelGroup>

                              </h:panelGrid>

                              <h:panelGrid width="400" columns="3">

                                  <a4j:commandButton value="Guardar" action="#{crearFuenteMB.asociarColumnaArchivo}" oncomplete="#{rich:component('asociacionCampoBDFormPopup')}.hide(); return false;" />

                                  <a4j:commandButton value="Continuar" action="#{crearFuenteMB.cerrar}" oncomplete="#{rich:component('asociacionCampoBDFormPopup')}.hide(); #{rich:component('asociacionCampoBDPopup')}.show(); return false;" />

                                  <a4j:commandButton value="Cancelar" action="#{crearFuenteMB.cerrar}" onclick="#{rich:component('asociacionCampoBDFormPopup')}.hide(); return false;" immediate="true" />

                              </h:panelGrid>

                      </h:form>

                     </rich:popupPanel>

       

      The problem is when a checkbox is selected for the first time, an ajax request is sent but it doesn't execute the valueChangeListerner method, but in the second request (when other checkbox is selected) the valueChangeListener method is executed, this is the valueChangeListener method:

       

           public void mostrarFormAsociarColumnaBD(ValueChangeEvent event) {

       

              ejecutarJS = (Boolean) event.getNewValue();

              nombreColumna = event.getComponent().getAttributes()

                      .get("nombreColumna").toString();

       

              if (ejecutarJS)

                  columna.setNombre((columna.getNombre() != null ? columna

                          .getNombre() + ", " : "")

                          + nombreColumna);

              else

                  columna.setNombre(columna.getNombre().replace(nombreColumna + ", ",

                          ""));

          }

       

      The managed bean is @SessionScoped.

      I'm using JSF 2.0 and Richfaces 4.0, JBoss AS 6

       

      What could be the problem?? any ideas??

       

      Than you already and I hope you understand the problem

       

      Cheers