13 Replies Latest reply on Mar 10, 2011 7:48 AM by ilya_shaikovsky

    a4j:repeat 2

    snaker

      I have a problem with a list, and i print a table of this form:

       

      <table>

          <tr>

                <th></th>

                ....

          </tr>

          <a4j:repeat id="ITP" var="d" value="#{bean.item.itemlist}" rowKeyVar="numP">

                <a4j:repeat id="ITR" var="r" value="#{d.moreItems}" rowKeyVar="numR">

                    <tr>

                              <td><h:inputText id="numPackages" value="#{r.element}"/></td> <!---Initially, value = 0-->

                              ....

                    </tr>

                </a4j:repeat>

          </a4j:repeat>

          </table>

       

      i add elements to my list.

      but if i modify the inputText, when i pulse a commadButtom (for ajax or for action do the same), only save the last  element "d",  the rest of  "d" elements return value to zero

       

      Help!!!

        • 1. Re: a4j:repeat 2
          boy18nj
          but if i modify the inputText, when i pulse a commadButtom (for ajax or for action do the same), only save the last  element "d",  the rest of  "d" elements return value to zero

          I did not understood these lines. If possible provide a snapshot to see how your list looks like.

          • 2. a4j:repeat 2
            snaker

            When  i include for example value "1" in inputText or inputNumberSpinner, in first line (d1 r1), in second line (d1 r2),and third line(d2 r1).

            when i put all values and i push the buttom, all values return to 0 except the last line (d2 r1).

            d1 r1 = 0

            d1 r2 = 0

            d2 r1 = 1

             

            if i have 4 "d"

             

            d1 r1 = 1

            d2 r1 = 1

            d3 r1 = 1

            d4 r1 = 1

             

            when i push the buttom all values to zero except fourth line

             

            d1 r1 = 0

            d2 r1 = 0

            d3 r1 = 0

            d4 r1 = 1

             

            ,imagen.png

            • 3. a4j:repeat 2
              boy18nj

              now it makes sense, please post your full xhtml code. My main concern is I want to see your h:form wrappers. Sorry I should have asked earlier.

              • 4. a4j:repeat 2
                snaker

                <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
                <ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:h="http://java.sun.com/jsf/html"
                    xmlns:a4j="http://richfaces.org/a4j"
                    xmlns:rich="http://richfaces.org/rich"
                    xmlns:f="http://java.sun.com/jsf/core"
                    xmlns:ui="http://java.sun.com/jsf/facelets"
                template="/plantillas/plantilla.xhtml">
                <ui:define name="cabecera"/>

                <ui:define name="contenido">

                <div id="CuerpoPagina">

                   <f:view>

                    <h:form id="formulario" >

                     <f:event type="preRenderView" listener="#{acceso.comprobarUsuario}"/>

                     <rich:panel id="panel" header="Receta Electronica" headerClass="titulo2" style="height:657px;">

                <rich:extendedDataTable var="prescripcion" value="#{rElectronica.listaP}" selection="#{rElectronica.seleccion}" footerClass="pieExtTabla" rendered="#{not empty rElectronica.consultaOUT.prescripciones}">

                       <a4j:ajax execute="@form" event="selectionchange" listener="#{rElectronica.seleccionListener}" render=":res" />

                       <f:facet name="header">

                        <h:outputText value="Prescripciones"/>

                       </f:facet>

                       <rich:column width="150px" rendered="false">

                        <f:facet name="header">

                          <h:outputText value="Orden Tratamiento"  style="white-space:nowrap"/>

                        </f:facet>

                        <div class="centrado"><h:outputText value="#{prescripcion.numOrdenTratamiento}"/></div>

                       </rich:column>

                       <rich:column width="110px">

                                       <f:facet name="header">

                                           <h:outputText value="Tipo Receta" />

                                       </f:facet>

                                       <div class="centrado">

                                        <h:outputText value="Receta Electrónica" rendered="#{prescripcion.idPrescripcion eq 0}"/>

                                        <h:outputText value="#{prescripcion.idReceta}" rendered="#{prescripcion.idReceta ne 0}"/>

                                       </div>

                                   </rich:column>

                       <rich:column width="90px">

                                       <f:facet name="header">

                                           <h:outputText value="Código" />

                                       </f:facet>

                                       <div class="centrado">

                                        <h:outputText value="#{prescripcion.medicamento.presentacion.codigoMedicamento}" rendered="#{empty prescripcion.medicamento.especialidad.codigoMedicamento}"/>

                                        <h:outputText value="#{prescripcion.medicamento.especialidad.codigoMedicamento}" rendered="#{not empty prescripcion.medicamento.especialidad.codigoMedicamento}"/>

                                       </div>

                                   </rich:column>

                                  

                                   <rich:column width="390px">

                                       <f:facet name="header">

                                           <h:outputText value="Medicamento" />

                                       </f:facet>

                                       <div class="centrado">

                                        <h:outputText value="#{prescripcion.medicamento.presentacion.nombreMedicamento}" rendered="#{empty prescripcion.medicamento.especialidad.codigoMedicamento}"/>

                                        <h:outputText value="#{prescripcion.medicamento.especialidad.nombreMedicamento}" rendered="#{not empty prescripcion.medicamento.especialidad.codigoMedicamento}"/>

                                       </div>

                                   </rich:column>

                                  

                       <rich:column width="80px">

                                       <f:facet name="header">

                                           <h:outputText value="Envases" />

                                       </f:facet>

                                       <div class="centrado"><h:outputText value="#{prescripcion.envasesPrescritos}" /></div>

                                   </rich:column>

                                  

                                   <rich:column width="80px">

                                       <f:facet name="header">

                                           <h:outputText value="Bloqueados" />

                                       </f:facet>

                                       <div class="centrado"><h:outputText value="#{prescripcion.envasesBloqueados}" /></div>

                                   </rich:column>

                                    <rich:column width="177px"><!-- 27 + 150px de la orden de tratamiento -->

                                       <f:facet name="header"/>

                                       <div class="centrado">

                                        

                <!--WITH THIS BUTTOM ADD TO LIST-->

                 

                 

                                        <h:commandButton image="/Imagenes/iconos/iconoDispensacion.gif" style="height:15px;width:20px" title="Dispensar" rendered="#{(not prescripcion.hayAnulacion or prescripcion.idReceta eq 0) and rElectronica.puedeDispensar}">

                                         <f:param name="ordenTratamiento" value="#{prescripcion.numOrdenTratamiento}"/>

                                         <f:param name="idReceta" value="#{prescripcion.idReceta}"/>

                                         <a4j:ajax event="click" execute="@form" render="@form ListaDispensaciones" listener="#{rElectronica.insertarDispensacion}"/>

                                        </h:commandButton>

                 

                                        <h:commandButton image="/Imagenes/iconos/Eliminar.png" style="height:15px;width:15px;margin-right:5px;" title="Anular Envases" rendered="#{not prescripcion.hayAnulacion and (not prescripcion.hayDispensacion or prescripcion.idReceta eq 0) and rElectronica.puedeDispensar}">

                                         <f:param name="ordenTratamiento" value="#{prescripcion.numOrdenTratamiento}"/>

                                         <f:param name="idReceta" value="#{prescripcion.idReceta}"/>

                                         <a4j:ajax event="click" execute="@form" render="@form ListaAnulaciones" listener="#{rElectronica.insertarAnulacion}"/>

                                        </h:commandButton>

                                        <h:commandButton image="/Imagenes/iconos/Bloquear3.png" style="height:15px;width:15px;margin-right:5px;" title="Bloquear Envases" rendered="#{rElectronica.puedeBloquear and prescripcion.idReceta eq 0 and not prescripcion.hayBloqueo}">

                                         <f:param name="numOrdenTratamiento" value="#{prescripcion.numOrdenTratamiento}"/>

                                         <f:param name="idReceta" value="#{prescripcion.idReceta}"/>

                                         <a4j:ajax event="click" execute="@form" render="@form ListaBloqueos" listener="#{rElectronica.insertarBloqueo}"/>

                                        </h:commandButton>

                                        <h:commandButton image="/Imagenes/iconos/Actualizar.png" style="height:15px;width:15px;margin-right:5px;" title="Replanificar Tratamiento">

                                         <f:param name="ordenTratamiento" value="#{prescripcion.numOrdenTratamiento}"/>

                                         <f:param name="codigoPresentacion" value="#{prescripcion.medicamento.presentacion.codigoMedicamento}"/>

                                        </h:commandButton>

                                        <h:commandButton image="/Imagenes/iconos/Grafica.png" style="height:15px;width:15px;margin-right:5px;" title="Ver Grafico Tratamientos">

                                         <f:param name="ordenTratamiento" value="#{prescripcion.numOrdenTratamiento}"/>

                                         <f:param name="codigoPresentacion" value="#{prescripcion.medicamento.presentacion.codigoMedicamento}"/>

                                        </h:commandButton>

                                        <h:commandButton image="/Imagenes/iconos/Historico2.png" style="height:15px;width:15px" title="Historial Paciente">

                                         <f:param name="ordenTratamiento" value="#{prescripcion.numOrdenTratamiento}"/>

                                         <f:param name="codigoPresentacion" value="#{prescripcion.medicamento.presentacion.codigoMedicamento}"/>

                                        </h:commandButton>

                                       </div>

                                   </rich:column>

                <rich:panel id="ListaDispensaciones" style="overflow-y:auto;height:170px;"  rendered="#{not empty rElectronica.listaDispensacion.dispensaciones or not empty rElectronica.listaAnulacion.dispensaciones}">

                       <ui:fragment rendered="#{not empty rElectronica.listaDispensacion.dispensaciones}">

                    

                 

                 

                 

                 

                 

                 

                 

                 

                 

                 

                 

                 

                 

                 

                 

                 

                 

                 

                 

                 

                 

                 

                 

                 

                 

                 

                 

                 

                 

                 

                 

                 

                 

                 

                 

                 

                 

                 

                 

                 

                 

                 

                 

                 

                 

                 

                 

                 

                <!--THIS IS THE TABLE THAT I EXPLAIN BEFORE -->

                 

                 

                        <table class="tabla1" style="border-collapse: collapse;width:98%;">

                         <tr><th class="captionTablas1" colspan="9">Dispensaciones</th></tr>

                         <tr>

                          <td class="cabeceraTabla1" style="width: 5%"><h:outputText value="Tipo"/></td>

                          <td class="cabeceraTabla1" style="width: 7.5%"><h:outputText value="Producto"/></td>

                          <td class="cabeceraTabla1" style="width: 7.5%"><h:outputText value="Envases"/></td>

                          <td class="cabeceraTabla1" style="width: 7.5%"><h:outputText value="Precio"/></td>

                          <td class="cabeceraTabla1" style="width: 7.5%"><h:outputText value="Aportación"/></td>

                          <td class="cabeceraTabla1" style="width: 20%"><h:outputText value="Sustitución"/></td>

                          <td class="cabeceraTabla1" style="width: 25%"><h:outputText value="Diligencia"/></td>

                          <td class="cabeceraTabla1" style="width: 15%"><h:outputText value="M. Genéricos"/></td>

                          <td class="cabeceraTabla1" style="width: 5%"></td>

                         </tr>

                         <a4j:repeat id="ITPrescripcion" var="dispensacion" value="#{rElectronica.listaDispensacion.dispensaciones}" rowKeyVar="numPrescripcion">

                          <a4j:repeat id="ITReceta" var="receta" value="#{dispensacion.recetas}" rowKeyVar="numReceta">

                           <tr>

                            <td class="bordeFilaTabla1">

                             <h:outputText value="R.I" rendered="#{receta.idPrescripcionRecetaImpresa ne 0}"/>

                             <h:outputText value="R.E" rendered="#{receta.idPrescripcionRecetaImpresa eq 0}"/>

                            </td>

                            <td class="bordeFilaTabla1">

                             <h:inputText id="codigoProducto" value="#{receta.codigoProductoDispensado}" style="width:50px;"/>

                             </td>

                            <td class="bordeFilaTabla1"><rich:inputNumberSpinner value="#{receta.envasesDispensados}" maxValue="10"/></td>

                            <td class="bordeFilaTabla1"><h:inputText value="#{receta.precioUnitario}" style="width:40px;"/></td>

                            <td class="bordeFilaTabla1"><h:inputText value="#{receta.aportacionTotal}" style="width:40px;"/></td>

                            <td class="bordeFilaTabla1">

                             <rich:select defaultLabel="Tipo Sustitución">

                              <f:selectItems value="#{rElectronica.listaMotivos}"/>

                             </rich:select>

                            </td>

                            <td class="bordeFilaTabla1"><h:inputTextarea value="#{receta.diligencias}" rows="1" style="width:98%"/></td>

                            <td class="bordeFilaTabla1">

                             <ui:repeat var="p" value="#{rElectronica.consultaOUT.prescripciones}">

                              <ui:fragment rendered="#{p.numOrdenTratamiento eq dispensacion.numOrdenTratamiento and not empty p.medicamentosPresentacion}">

                               <select id="seleccionMedicamento" onchange="medicamentosGenericos(this,#{numPrescripcion},#{numReceta});" style="width: 100px;">

                                <option id="0" value="0" >Medicamentos</option>

                                <ui:repeat var="medicamentos" value="#{p.medicamentosPresentacion}">

                                 <option id="#{medicamentos.codigoMedicamento}" value="#{medicamentos.nombreMedicamento}">#{medicamentos.nombreMedicamento}</option>

                                </ui:repeat>

                               </select>

                              

                              </ui:fragment>

                             </ui:repeat>

                            </td>

                            <td class="bordeFilaTabla1">

                             <h:commandButton id="BEliminarDispensacion" image="/Imagenes/iconos/Eliminar.png" title="Eliminar línea de dispensación"  style="padding-top:2px">

                              <f:param name="numOrdenTratamiento" value="#{dispensacion.numOrdenTratamiento}"/>

                              <f:param name="idReceta" value="#{receta.idPrescripcionRecetaImpresa}"/>

                              <f:param name="indicePrescripcion" value="#{numPrescripcion}"/>

                              <f:param name="indiceReceta" value="#{numReceta}"/>

                              <f:ajax execute="@form" render="@form BEliminarDispensacion" event="click" listener="#{rElectronica.eliminarDispensacion}"/>

                             </h:commandButton>

                            </td>

                           </tr>

                          </a4j:repeat>

                         </a4j:repeat>

                        </table>

                         

                       </ui:fragment>

                       <ui:fragment rendered="#{not empty rElectronica.listaAnulacion.dispensaciones}">

                        <table class="tabla1" style="border-collapse: collapse;width:98%;">

                         <tr><th class="captionTablas1" colspan="4">Anulaciones</th></tr>

                         <tr>

                          <td class="cabeceraTabla1" style="width: 15%"><h:outputText value="Tipo Receta"/></td>

                          <td class="cabeceraTabla1" style="width: 45%"><h:outputText value="Producto"/></td>

                          <td class="cabeceraTabla1" style="width: 35%"><h:outputText value="Envases"/></td>

                          <td class="cabeceraTabla1" style="width: 5%"></td>

                         </tr>

                         <a4j:repeat id="ITAPrescripcion" var="dispensacion" value="#{rElectronica.listaAnulacion.dispensaciones}" rowKeyVar="numPrescripcion">

                          <a4j:repeat id="ITAReceta" var="receta" value="#{dispensacion.recetas}" rowKeyVar="numReceta">

                           <tr>

                            <td class="bordeFilaTabla1">

                             <h:outputText value="R.E" rendered="#{empty receta.idPrescripcionRecetaImpresa}"/>

                             <h:outputText value="R.I" rendered="#{not empty receta.idPrescripcionRecetaImpresa}"/>

                            </td>

                            <td class="bordeFilaTabla1"><h:outputText value="#{receta.codigoProductoDispensado}"/> </td>

                            <td class="bordeFilaTabla1"><rich:inputNumberSpinner value="#{receta.envasesDispensados}" maxValue="10"/></td>

                            <td class="bordeFilaTabla1">

                             <h:commandButton id="BEliminarAnulacion" image="/Imagenes/iconos/Eliminar.png" title="Eliminar línea de dispensación"  style="padding-top:2px">

                              <f:param name="numOrdenTratamiento" value="#{dispensacion.numOrdenTratamiento}"/>

                              <f:param name="idReceta" value="#{receta.idPrescripcionRecetaImpresa}"/>

                              <f:param name="indicePrescripcion" value="#{numPrescripcion}"/>

                              <f:param name="indiceReceta" value="#{numReceta}"/>

                              <f:ajax execute="@form" render="@form BEliminarAnulacion" event="click" listener="#{rElectronica.eliminarAnulacion}"/>

                             </h:commandButton>

                            </td>

                           </tr>

                          </a4j:repeat>

                         </a4j:repeat>

                        </table>

                         

                       </ui:fragment>

                       <div style="width: 98%" align="center">

                        <h:outputText value="DNI: " styleClass="etiqueta1"/>

                        <h:inputText id="DNI" value="#{rElectronica.dniRecoge}" onkeypress="return prueba(event);"/> 

                       

                        <h:commandButton action="#{rElectronica.paginaResultadoDispensacionElectronica}" value="Dispensar" >

                         <a4j:ajax execute="@form" render="@form formulario" event="click"/>

                        </h:commandButton>

                       </div>

                      </rich:panel>

                • 5. a4j:repeat 2
                  snaker

                  if you don't understand something, tell me

                  • 6. a4j:repeat 2
                    boy18nj

                    Your posted code is not complete, I wasn't able to validate your xhtml.

                     

                    I see in your code, you have defined method inside your listener to save the values. If this is correct, since you are editing mutliple values on the form, but when the save is clicked the framework is always going to save the row which has focus (try to edit only 1st row then click save, check if only 1st row is saved). In your case it is the last row. In the listener methd only 1 row is passed. Now it depends on your save method, which rows you are trying to save.

                     

                    I would advise you to have save button next to each row.

                     

                    Let me know if this helps.

                    • 7. a4j:repeat 2
                      snaker

                      o, but i don't understand why do it...

                      i use this buttom

                      <h:commandButton action="#{rElectronica.paginaResultadoDispensacionElectronica}" value="Dispensar" />

                      it do submit, and in my bean only get values of my last elemet of my List, it would get all values!!

                      There is another way?

                      • 8. a4j:repeat 2
                        snaker

                        sorry i forget to say that not save the last row, save the last element.

                        Example:

                         

                        d1 r1 = 1

                        d1 r2 = 1

                        d2 r1 = 1

                        d2 r2 = 1

                        d3 r1 = 1

                        d3 r2 = 1

                         

                        when i do submit:

                         

                        d1 r1 = 0

                        d1 r2 = 0

                        d2 r1 = 0

                        d2 r2 = 0

                        d3 r1 = 1

                        d3 r2 = 1

                        • 9. a4j:repeat 2
                          ilya_shaikovsky

                          which version used? I tried to add change output components to input ones at demosite and use ajax submit - but seeing all the values passed to server and returned back to client correctly with the latest snapshot..

                          • 10. a4j:repeat 2
                            snaker

                            Rich Faces 4 M6

                            • 11. a4j:repeat 2
                              ilya_shaikovsky
                              • 12. a4j:repeat 2
                                snaker

                                i try with cr1 but it do the same

                                • 13. a4j:repeat 2
                                  ilya_shaikovsky

                                  we checked once more and still can't confirm. We need minimal sample for further investigations.