jsf 2 - Print data from dynamic table in JSF -
i have screen dynamic table contains inputtext feild , selectnemenu beside there's (+) button, when user should press button form should add row below ,i want print on console(eclipse) data user enter , want add validation (+) button user cant add new row until user enter data in cells in previous row
iam newbie jsf programming.can tell me basic example.
you may use f:setpropertyactionlistener h:commandbutton values of current row in backing bean. , in backing bean may apply validation check values of inputtext , selectonemenu. if values non empty can add new object (row) list below :
jsf code:
<h:datatable id="dt" var="element" value="#{bean.list}"> <h:column> <h:inputtext value="#{element.inputval}" > </h:inputtext> </h:column> <h:column> <h:selectonemenu value="" > </h:selectonemenu> </h:column> <h:column> <h:commandbutton value="plus button" action="#{bean.addrow}"> <f:setpropertyactionlistener value="#{element}" target="#{bean.selectedrow}" /> </h:commandbutton> </h:column> </h:datatable>
bean code :
public void addrow() { if(validateemptyrow(selectedrow) { a = new a(); list.add(a); } else { //print validation message } } public boolean validateemptyrow(a selectedrow){ boolean flag = true; if(null == selectrow.getinputval()){ flag = false; } //similary validate null value selectonemenu , return boolean value false if of 2 having null or empty value return flag; } //define getter setter selectedrow, list etc
Comments
Post a Comment