Thus, as in your example, you get three forms (or how long the list will be there). No means available to keep them together at once.
Forms work independently of each other.
The form should frame all its fields and buttons.
Then you write in datatable var="value" , and in column use some kind of data . What name was given to the variable is what should be used.
<h:form> ... <h:dataTable value="#{datacontroller.list}" styleClass="table table-bordered" var="data"> <h:column> <f:facet name="header">Data</f:facet> <h:inputText value="#{data.inputvalue}"/> </h:column> </h:dataTable> ... <h:commandButton value="Ok" action="#{datacontroller.calculate}"/> ... </h:form>
Controller
public class Datacontroller { private List<Data> list; ... List<Data> getList() { if (list == null) list = ... // создать и заполнить return list; } ... public void calculate() { ... for (Data data : getList()) { String inputvalue = data.getInputvalue(); ... } ... } }
Data
public class Data { private String inputvalue; public String getInputvalue() { return inputvalue; } public void setInputvalue(String inputvalue) { this.inputvalue = inputvalue; } }
If data is a List<String> , then here https://stackoverflow.com/questions/21236170/using-hdatatablehinputtext-on-a-liststring-doesnt-update-model-values
<h:form> ... <h:dataTable value="#{datacontroller.list}" styleClass="table table-bordered" var="data" binding="#{table}"> <h:column> <f:facet name="header">Data</f:facet> <h:inputText value="#{datacontroller.list[table.rowIndex]}"/> </h:column> </h:dataTable> ... <h:commandButton value="Ok" action="#{datacontroller.calculate}"/> ... </h:form>
You can change the list item by index. To get the index in this case, use the method with the table's binding to the variable table . Through table we get the ability to extract the properties of the table (and not only). So table.rowIndex is the index of the current row. What we need. The table variable itself is created automatically in the request scope.
Controller
public class Datacontroller { private List<String> list; ... List<String> getList() { if (list == null) list = ... // создать и заполнить return list; } ... public void calculate() { ... for (String data : getList()) { ... } ... } }