Event.getObject () in editing line for boards sends old value to bean

I am trying to use a simple facet function that allows a user to edit row data in a table itself. I followed this link to achieve it:

http://www.primefaces.org/showcase/ui/datatableRowEditing.jsf

When I tell the edit user, the newly entered values โ€‹โ€‹are not sent to the bean. It still shows only old values.

My code in JSF:

<p:dataTable value="#{mybean.userList}" var="item" id="dataTab" widgetVar="usersTable" tableStyleClass="data" paginator="true" rows="5" filteredValue="#{userController.filteredUsers}" editable="true" rowKey="#{item}"> <p:ajax event="rowEdit" listener="#{mybean.onEdit}" update=":userForm:growl" /> <p:ajax event="rowEditCancel" listener="#{mybean.onCancel}" update=":userForm:growl" /> <f:facet name="header"> <p:outputPanel> <h:outputText value="Search all fields:" /> <p:inputText id="globalFilter" onkeyup="('usersTable').filter()" style="width:150px" /> </p:outputPanel> </f:facet> <p:column sortBy="#{item.firstName}" filterBy="#{item.firstName}" filterMatchMode="startsWith"> <p:cellEditor> <f:facet name="header"> <h:outputText value="First Name" /> </f:facet> <f:facet name="output"> <h:outputText value="#{item.firstName}" /> </f:facet> <f:facet name="input"> <p:inputText value="#{item.firstName}" style="width:100%"/> </f:facet> </p:cellEditor> </p:column> <p:column sortBy="#{item.lastName}" filterBy="#{item.lastName}" filterMatchMode="startsWith"> <p:cellEditor> <f:facet name="header"> <h:outputText value="Last Name" /> </f:facet> <p:column headerText="Update" style="width:6%"> <p:rowEditor /> </p:column> </p:dataTable> 

My bean code:

 public String onEdit(RowEditEvent event) { User user=(User)event.getObject()); user.getFirstName(); } 

in bean to get the list in ui:

  public List<UserBean> getUsersList(){ List<UserBean> retval = new ArrayList<>(); for (Object[] tuple : myFacade.getUserList()) { UserBean ub = new UserBean(); ub.setFirstName((String) tuple[0]); ub.setLastName((String)tuple[1]); ub.setEmailAddress((String)tuple[2]); ub.setOfficeNumber((String)tuple[3]); ub.setRole((String)tuple[4]); retval.add(ub); } return retval; } 

I tried the suggestions that were indicated in some posts, but they did not work. Can anyone let me know how I can get new values. I am using glassfish 4.0, primefaces 3.5.

+6
source share
1 answer

I managed to find out the problem. Every time I get a list in the getter method, I call the database to load the data. But this needs to be done only if the list is null. The following code gives you a clear image:

 public List<UserBean> getUsersList(){ if(retval == null) { retval = new ArrayList<>(); for (Object[] tuple : myFacade.getUserList()) { UserBean ub = new UserBean(); ub.setFirstName((String) tuple[0]); ub.setLastName((String)tuple[1]); ub.setEmailAddress((String)tuple[2]); ub.setOfficeNumber((String)tuple[3]); ub.setRole((String)tuple[4]); retval.add(ub); } } return retval; } 

So getUsersList is my var value in p: datatable, and now when I call onEdit, it checks the list if it is null, it invokes a database call or does not invoke a database.

+8
source

Source: https://habr.com/ru/post/955123/


All Articles