primefaces - Saving data from multiple inputtext boxes created by a loop in jsf -


basically, have input text box want submit each item in array. code below cut down relevant portions

<c:foreach items="${mybean.mats}" var="mat">         <p:datatable var="datarow" value="#{mybean.getdatarows(mat.itemid)}" rowindexvar="row">             <p:column>                 <p:inputtext value="#{bean.amt}" />             </p:column>         </p:datatable>     </p:panel>      <p:commandbutton value="confirm" action="#{mybean.runsubmit}" process="@this" /> </c:foreach> 

from know, each individual item needs have own variable name save data in each input text box. know method i'm using wrong, there way save data? perhaps in array or something?

first, mixing jstl c:foreach datatable not recommended. use ui:repeat instead.

second, p:datatable value has reference collection exists during lifetime of backing bean. looks me call #{mybean.getdatarows(mat.itemid)} generates list of items dynamically. that's going problem since backing bean need call getdatarows when values re-applied bean on ajax call runsubmit save values. in case, need save dynamically created list backing bean same collection match collection used produce html.

for example, suppose backing bean contains property list<list<mat>> mats, mat class contains single property 'dataid'. then, el be:

<h:form id="input-form">  <ui:repeat id="mats-repeat" value="#{mats}" var="mat">   <p:datatable id="mat-table" value="#{mat}" var="dataobj">    <p:column>     <p:inputtext id="dataid" value="#{dataobj.dataid}" />    </p:column>   </p:datatable>  </ui:repeat> </h:form> 

since form, repeat, , datatable components naming containers, ensure child components named uniquely. in case, first input mat element rendered as:

<input id="input-form:mats-repeat:0:mat-table:0:dataid" ... 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -

django - CSRF verification failed. Request aborted. CSRF cookie not set -