0

I want to add a list of elements in a form in a Java jsf app.

<h:form id="producto-nuevo">
    <div class="col-sm-12 col-md-6">
        <p:panelGrid columns="2" layout="grid">
            <h:outputText value="Nombre"></h:outputText>
            <h:inputText value="#{productoView.productoNombre}"></h:inputText>
        </p:panelGrid>
    </div>


    <p:commandButton value="Agregar Atributo"
                     actionListener="#{productoView.addAtributo()}"  
                     update="atributoslist"> 
    </p:commandButton>  
    <div class="col-sm-12">
        <h:panelGroup id="atributoslist">
            <h:form>                                
                <ui:repeat value="#{productoView.atributos}"  var="atributo">
                    <div class="col-sm-6 col-md-4">
                        <div class="form-group">
                            <p:outputLabel value="nombre:" class="col-sm-12" />
                            <p:inputText value="#{atributo.nombre}" class="col-sm-12" />
                        </div>
                        <div class="form-group">
                            <p:outputLabel value="valor" class="col-sm-12" />
                            <p:inputText value="#{atributo.valor}" class="col-sm-12" />
                        </div>
                    </div>
                </ui:repeat>
            </h:form>
        </h:panelGroup>
    </div>          

    <h:commandButton value="Guardar Producto"
                     action="#{productoView.crearProducto}">
    </h:commandButton>
</h:form>

But when I add a new element the old fields are set empty.

Is it possible to add a new field without losing the values ​?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Maske
  • 824
  • 2
  • 17
  • 35
  • Did you try to use a datatable of primefaces http://www.primefaces.org/showcase/ui/data/datatable/basic.xhtml – Youcef LAIDANI Jun 12 '16 at 07:17
  • 1
    Please note this about nested forms: http://stackoverflow.com/questions/7371903/how-to-use-hform-in-jsf-page-single-form-multiple-forms-nested-forms?lq=1 – sinclair Jun 12 '16 at 11:55

0 Answers0