Select Row in DataTable: getRowData()

I am a beginner in JSF. Recently need to develop web appl with back-end db. but having problem in selecting row in data table. i read other posting and tried all method but still get error msg. please help.

my code indataTable back bean:

public String select()throws SQLException{

// 1st method try pulling data to UIData UItable by ResultSet

//ResultSet rs = (ResultSet)UItable.getRowData();

PhyBean physician =new PhyBean();

//physician.setLicno(rs.getString("LICNO"));

// 2nd method try pull data to HtmlDataTable table

//PhyBean physician = new PhyBean();

physician = (PhyBean)table.getRowData();

return"gotOne";

}

my code in jps:

<h:dataTable value="#{dataTable.all}" var="dataTable">

<h:column>

<h:commandLink value="view" action="#{dataTable.select}"/>

</h:column>

please help. Thx.

[1399 byte] By [wingshana] at [2007-11-27 1:40:18]
# 1
Check http://balusc.xs4all.nl/srv/dev-jep-dat.html how to use datatables.There are lots of examples there.
BalusCa at 2007-7-12 0:54:23 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

thx BalusC but I read that article already. the way that i pull information is by coding like this:

ResultSet result = displayQuery.executeQuery();

return ResultSupport.toResult(result);

but i tried to use the getRowData() to put information into either the UIData or HtmlDataTable. but both ways give me errors. those method are found from that article and some replies in this forum. pls help. thx alot.

wingshana at 2007-7-12 0:54:23 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

First,

<h:dataTable value="#{dataTable.all}" var="dataTable">

You're overwriting the managed bean name with the name of the iterated row object.

Give it another unique name, for example:<h:dataTable value="#{dataTable.all}" var="row">

BalusCa at 2007-7-12 0:54:23 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

Sorry BalusC, once I called the getRowData() function, it will give me the null pointer exception.

even if i try this:

if((PhyBean)table.getRowData()==null){

return "error";

}else{

return "gotOne";

}

it still give me that nullpointer exception. thx

wingshana at 2007-7-12 0:54:23 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5
Is the "table" actually bound to the dataTable?
BalusCa at 2007-7-12 0:54:23 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6
thx i bound the "table" into the data table as binding="#{dataTable.table}"but sorry still got another error: #{dataTable.test}: javax.faces.el.EvaluationException: java.lang.ClassCastException: java.util.TreeMappls...thx
wingshana at 2007-7-12 0:54:23 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7

The HtmlDataTable value expects a List or a DataModel. Not a Map.

Once more: read http://balusc.xs4all.nl/srv/dev-jep-dat.html how to use datatables. All issues and questions here are covered there. I suggest you to start off from scratch again using this article until you get it working. Then extend it further on your own.

BalusCa at 2007-7-12 0:54:23 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 8

Ok, one last question, because i was coding to put all records to the database by doing:

public Result getAll(){

:

:

return ResultSupport.toResult(result);

}

because in the article the data was firstly put into a list and then published to the web... will that make a difference if i did it by returning a "Result"?

Thanks.

wingshana at 2007-7-12 0:54:23 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 9
Are you talking about ResultSet? If so, wrap it in [url= http://dsc.sun.com/docs/jscreator/apis/jsf/javax/faces/model/ResultSetDataModel.html]ResultSetDataModel[/url].
BalusCa at 2007-7-12 0:54:23 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 10
The page you gave http://balusc.xs4all.nl/srv/dev-jep-dat.html is useful!I am reading it now :)
yellowbeea at 2007-7-12 0:54:23 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...