1 Reply Latest reply on Feb 14, 2011 10:36 AM by gatosk8

    how to reRender a Textbox with an action in a modalPanel?

    gatosk8

      Hi,I'm new in this foro and I have a problem for some time and i don't know how to solve it.


      I have a textbox where I need to enter a value of a enterprise and next to this textbox there is a link that opens a modal panel and where I choose an enterprise and the name of this must be loaded into the textbox.


      here is de .xhtml





      <s:decorate id="conEmprsaField" template="../layout/display.xhtml">
          <ui:define name="label">Empresa</ui:define>
          <h:inputText id="txtEmpresa1" 
              disabled="true"
                value="#{SeleccionarEmpresa.cogerEmpresa().emrNombre}" />
          <a:commandLink style="color:#880000" 
                      ajaxSingle="true" 
                      value="Seleccionar" 
                      onclick="Richfaces.showModalPanel('empresaModalPanel', {top:'10px', left:'10px', height:'400px'});">
      </s:decorate>






      Here is the modal in which i selected the enterprise to be loaded into the textbox.




       <rich:modalPanel id="empresaModalPanel" width="350" height="100">
              <f:facet name="header">
                  <h:panelGroup>
                      <h:outputText value="Empresas"></h:outputText>
                  </h:panelGroup>
              </f:facet>
              
             <h:form> 
                   <rich:datascroller for="empresaList" maxPages="5"/>
                   <rich:dataTable id="empresaList" rows="10"
                                         var="_empresa"
                                        value="#{empresaList.resultList}"
                                          rendered="#{not empty empresaList.resultList}">
                        <h:column>
                            <f:facet name="header">Nombre</f:facet>
                            <h:outputText value="#{_empresa.emrNombre}"/>
                        </h:column>
                        <h:column>
                            <f:facet name="header">RUC</f:facet>
                            <h:outputText value="#{_empresa.emrNumruc}"/>
                        </h:column>                 
                        <rich:column styleClass="action">
                            <f:facet name="header">Acción</f:facet>
                            <a4j:commandLink value="Seleccionar" 
                                                ajaxSingle="true"                                           
                                                action="#{SeleccionarEmpresa.seleccionarEmpresa(_empresa)}"
                                                oncomplete="Richfaces.hideModalPanel('empresaModalPanel');"
                                                reRender="txtEmpresa1">     
                                                <a4j:ajaxListener type="org.ajax4jsf.ajax.ForceRender"/>
                                                </a4j:commandLink>
                        </rich:column>
                    </rich:dataTable>
                     <a4j:commandButton value="Cerrar" 
                                           ajaxSingle="true" 
                                           oncomplete="Richfaces.hideModalPanel('empresaModalPanel');"     />
                </h:form>
          </rich:modalPanel>
      





      and mi Bean is this.



      @Name("SeleccionarEmpresa")
      @Scope(CONVERSATION)
      public class ModalAgregarEmpresa extends EntityHome<Contacto>{
      
           private static final long serialVersionUID = -1901834046536422763L;
           
           private Empresa empresa;
           
           public Empresa getEmpresa() {
                return empresa;
                
           }
           
           public void seleccionarEmpresa(Empresa empresa) {          
                System.out.println("la empresa seleccionada es:------->"+empresa.getEmrNombre());
                setEmpresa(empresa);
                
           }
           
           public Empresa cogerEmpresa() {
                return getInstance() == null ? null : getInstance().getEmpresa();               
           }
      
           public void setEmpresa(Empresa empresa) {
                this.empresa = getEmpresa();
                
           }
           
           @Override
           protected Contacto createInstance() {
                Contacto contacto = new Contacto();
                return contacto;
           }
           
           public boolean isWired() {
                return true;
           }
           
           public Contacto getDefinedInstance() {
                return isIdDefined() ? getInstance() : null;
           }
      }
      



      The enterprise is selected but i can't put the value into de textbox when i do the reRender, if anyone can help my I'll be very grateful


      thanks in advance and sorry for my english :)







        • 1. Re: how to reRender a Textbox with an action in a modalPanel?
          gatosk8

          Well, I could finally find an answer to this problem ...
          if anyone is interested on this, here is the code that i use.



          .xhtml


          <s:decorate id="opoEmprsaField" template="../layout/display.xhtml">
                              <ui:define name="label">Empresa</ui:define>
                              <h:inputText id="txtEmpresa" 
                                          disabled="true"                                                                                                                                            
                                          value="#{SeleccionarModalEmpresa.empresaSeleccionada.emrNombre}" />
                              <a:commandLink style="color:#880000" 
                                          ajaxSingle="true" 
                                          value="Seleccionar" 
                                          onclick="Richfaces.showModalPanel('empresaModalPanel', {top:'10px', left:'10px', height:'400px'});"/>



          the modal panel


          <rich:modalPanel id="empresaModalPanel" width="350" height="100">
                  <f:facet name="header">            
                          <h:outputText value="Empresas"></h:outputText>           
                  </f:facet>
                  <f:facet name="controls">
                      <span style="cursor:pointer" onclick="javascript:Richfaces.hideModalPanel('empresaModalPanel')">[X]</span>
                  </f:facet>
                 <h:form> 
                      <rich:datascroller for="empresaList" maxPages="5"/>
                      <rich:dataTable id="empresaList" rows="10"
                                         var="_empresa"
                                        value="#{empresaList.resultList}"
                                         rendered="#{not empty empresaList.resultList}">
                          <h:column>
                              <f:facet name="header">Nombre</f:facet>
                              <h:outputText value="#{_empresa.emrNombre}"/>
                          </h:column>
                          <h:column>
                              <f:facet name="header">RUC</f:facet>
                              <h:outputText value="#{_empresa.emrNumruc}"/>
                          </h:column>               
                          <rich:column styleClass="action">
                              <f:facet name="header">Acción</f:facet>
                              <a4j:commandLink value="Seleccionar" 
                                              ajaxSingle="true"                                     
                                              action="#{SeleccionarModalEmpresa.seleccionarEmpresa(_empresa)}"
                                              oncomplete="Richfaces.hideModalPanel('empresaModalPanel');"
                                              reRender="txtEmpresa1">    
                                              <a4j:ajaxListener type="org.ajax4jsf.ajax.ForceRender"/>
                              </a4j:commandLink>
                          </rich:column>
                      </rich:dataTable>
                      <a4j:commandButton value="Cerrar" 
                                          ajaxSingle="true" 
                                          oncomplete="Richfaces.hideModalPanel('empresaModalPanel');"    />
                   </h:form>
              </rich:modalPanel>



          and the bean


          @Name("SeleccionarModalEmpresa")
          @Scope(CONVERSATION)
          public class SeleccionModalEmpresa extends EntityHome<Contacto>{
          
              private static final long serialVersionUID = -1901834046536422763L;
              
              private Empresa empresa;
              private Empresa empresaSeleccionada = new Empresa();
              
              
              public Empresa getEmpresa() {
                  return empresa;
                  
              }
              
              public void seleccionarEmpresa(Empresa empresa) {               
                  setEmpresa(empresa);
                  empresaSeleccionada=empresa;
                  
              }      
                          
              public void setEmpresa(Empresa empresa) {
                  this.empresa = getEmpresa();
                  
              }
              
              public Empresa getEmpresaSeleccionada() {
                  return empresaSeleccionada;
              }
          
              public void setEmpresaSeleccionada(Empresa empresaSeleccionada) {
                  this.empresaSeleccionada = empresaSeleccionada;
              }
              
              @Override
              protected Contacto createInstance() {
                  Contacto contacto = new Contacto();
                  return contacto;
              }
              
              public boolean isWired() {
                  return true;
              }
              
              public Contacto getDefinedInstance() {
                  return isIdDefined() ? getInstance() : null;
              }
          }