aspose file tools*
The moose likes JSF and the fly likes How to Reterive Row Data in JSF Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "How to Reterive Row Data in JSF" Watch "How to Reterive Row Data in JSF" New topic
Author

How to Reterive Row Data in JSF

Samiullah Niazi
Greenhorn

Joined: Aug 20, 2008
Posts: 1
Hi,
Can anybody help me in reteriving particular cell of data table in JSF. I want to select ID of selected row in DataTable.

Currenty I am using as follow.

private DataModel studentDataModel=null;

As I click on the data table printing as
System.out.println(studentDataModel.getRowData());
gives
{address=Karachi, id=4, name=Navaid, password=nabc, username=n1234}


So my question is how to retrieve id of selected row.

I also created bean as follow.

--------------------------------------------------
public class Student implements Serializable {

private long id;
private String name;
private String username;
private String password;
private String address;
--------------------------------------------------
and I am trying to reterive row as follow

Student studentInfo=null;
studentInfo= (Student) studentDataModel.getRowData();

but on clicking on the button following error is shown :-(

500 Internal Server Error

javax.faces.FacesException: #{tableData.selectRow}: javax.faces.el.EvaluationException: java.lang.ClassCastException: javax.faces.model.ResultSetDataModel$ResultSetMap
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:98)
at javax.faces.component.UICommand.broadcast(UICommand.java:332)
at javax.faces.component.UIData.broadcast(UIData.java:677)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:287)
at javax.faces.component.UIViewRoot.processDecodes(UIViewRoot.java:327)
at com.sun.faces.lifecycle.ApplyRequestValuesPhase.execute(ApplyRequestValuesPhase.java:99)
at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:268)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:110)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:213)
at com.evermind[Oracle Containers for J2EE 10g (10.1.3.3.0) ].server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:713)
at com.evermind[Oracle Containers for J2EE 10g (10.1.3.3.0) ].server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:370)
at com.evermind[Oracle Containers for J2EE 10g (10.1.3.3.0) ].server.http.HttpRequestHandler.doProcessRequest(HttpRequestHandler.java:871)
at com.evermind[Oracle Containers for J2EE 10g (10.1.3.3.0) ].server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:453)
at com.evermind[Oracle Containers for J2EE 10g (10.1.3.3.0) ].server.http.HttpRequestHandler.serveOneRequest(HttpRequestHandler.java:221)
at com.evermind[Oracle Containers for J2EE 10g (10.1.3.3.0) ].server.http.HttpRequestHandler.run(HttpRequestHandler.java:122)
at com.evermind[Oracle Containers for J2EE 10g (10.1.3.3.0) ].server.http.HttpRequestHandler.run(HttpRequestHandler.java:111)
at oracle.oc4j.network.ServerSocketReadHandler$SafeRunnable.run(ServerSocketReadHandler.java:260)
at com.evermind[Oracle Containers for J2EE 10g (10.1.3.3.0) ].util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:303)
at java.lang.Thread.run(Thread.java:595)
Caused by: javax.faces.el.EvaluationException: java.lang.ClassCastException: javax.faces.model.ResultSetDataModel$ResultSetMap
at com.sun.faces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:150)
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:92)
... 18 more
Caused by: java.lang.ClassCastException: javax.faces.model.ResultSetDataModel$ResultSetMap
at mathmatics.TableData.selectRow(TableData.java:79)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at com.sun.faces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:146)
... 19 more
Jerwin Louise Uy
Ranch Hand

Joined: Oct 27, 2007
Posts: 75
The table.getRowData() will return the corresponding object in the DataModel.

For example, if you set a ObjectA with a property id in the data table, table.getRowData() will give you ObjectA and not the property id.

So in your case, simply cast the object returned by the table.getRowData() to the appropriate type that contains your id.

Regards.


Uy Jerwin Louise Vergara
Junior Developer / Research and Development at Incuventure Partners Corporation
email: jerwin.uy@incuventure.net
 
Don't get me started about those stupid light bulbs.
 
subject: How to Reterive Row Data in JSF