This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: userModel.getRowIndex() is always returning the first row
 
Similar Threads
JSF 1.2 Facelets - Component ID form1:dataTable:j_id101 has already been found in the view
how to set and get h:selectBooleanCheckbox value in h:datatabel
getting object instance inside nested h:dataTable
JSF check box
dataTable troubles