File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSF and the fly likes userModel.getRowIndex() is always returning the first row Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "userModel.getRowIndex() is always returning the first row" Watch "userModel.getRowIndex() is always returning the first row" New topic
Author

userModel.getRowIndex() is always returning the first row

Pushpalatha Gowdra
Greenhorn

Joined: Jan 25, 2008
Posts: 18
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

Joined: Jan 25, 2008
Posts: 18
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: userModel.getRowIndex() is always returning the first row