Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to Reterive Row Data in JSF

 
Samiullah Niazi
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic