0

I have an "Add" button at the bottom that when clicked, I want it to duplicate part of form below the existing one. How to change automatic id and value for new inputs , I need this later for generating reports with all entries.

<h:panelGrid columns="2">
        <p:outputLabel value="From: " />
                <p:inputMask id="date1" value="#{data.date1}" mask="99/99/9999"/>
                    <p:outputLabel value="To: " />
                 <p:inputMask id="date2" value="#{data.date2}" mask="99/99/9999"/>
                    <p:outputLabel value="Name: " />
                <p:inputText id=name1    value="#{data.name}" />

                    <p:outputLabel value="Description: " />
                <p:inputTextarea id=description1 value="#{data.description}" />
                    </h:panelGrid>
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
digo
  • 25
  • 7

1 Answers1

0

i would do it this way:

create an ArrayList of your Data-Object example List<Data> dataList; in your ManagedBean, then use dataTable in the view to display the fields of each Data-Object.

when you click the "duplicate Button", an action/ajax methode could be called within your bean to duplicate or add new entries to the dataList, ...etc.

something like:

<h:dataTable var="data" value="#{bean.dataList}">
<h:column>
   <h:panelGrid columns="2">
        <p:outputLabel value="From: " />
        <p:inputMask id="date1" value="#{data.date1}" mask="99/99/9999"/>
        <p:outputLabel value="To: " />
        <p:inputMask id="date2" value="#{data.date2}" mask="99/99/9999"/>
        <p:outputLabel value="Name: " />
        <p:inputText id=name1    value="#{data.name}" />
        <p:outputLabel value="Description: " />
        <p:inputTextarea id=description1 value="#{data.description}" />
   </h:panelGrid>
</h:column>
</h:dataTable>
Rami.Q
  • 2,486
  • 2
  • 19
  • 30