• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

userModel.getRowIndex() is always returning the first row

 
Pushpalatha Gowdra
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a table with user data in ListDataModel called "userModel" with a getter method

public DataModel getUserModel() {
if(userModel == null)
userModel = new ListDataModel();
userModel.setWrappedData(search.getUsersList());

return userModel;
}

the jsp file using this table is :

<h:dataTable styleClass="table.data" rowClasses="evenRow, oddRow" headerClass="columnHeader" value="#{handleTable.userModel}" var="result" >
<h:column>
<f:facet name="header">
<hutputText value="#{labels.empId}"/>
</f:facet>
<h:commandLink action="#{navigate.updateUser}" immediate="true">
<hutputText value="#{result.empId}"/>
</h:commandLink>
</h:column>

and the action method linked with command link is:

public String updateUser(){

HttpSession session= (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);
DataModel userModel = ((DataTableHandler) session.getAttribute("handleTable")).getUserModel();

/*System.out.println("selected row: " + userModel.getRowIndex());
System.out.println("row available: " + userModel.isRowAvailable());*/

session.removeAttribute("user");
session.setAttribute("user",userModel.getRowData());

forUpdate = true;
return "updateUser";
}

But whats happening is, the userModel.getRowIndex() method is always returning zero "0", and hence the userModel.getRowData() method is always returning first row object.

Do I need to set the rowIndex manually?

Any help would be appriciated. Thanks in advance

Regards,
Pushpa
 
Pushpalatha Gowdra
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem resolved

The problem was in my getter method

public DataModel getUserModel() {
if(userModel == null)
userModel = new ListDataModel();
userModel.setWrappedData(search.getUsersList());

return userModel;
}

this method was setting the wrapper everytime we call the method getUserModel.

To make it work properly, I should write the method in the same class where getUserModel() is there, which will give me the getRowData() directly.
something like:

public Object getSelectedData() {
return userModel.getRowData();
}


And I shouldn't call getUserModel() to get the current model used by the dataTable in the backing bean. It should be used only in the jsf file, to construct the table.

Regards,
Pushpa
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic