Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

how to select a particular row in a DataTable  RSS feed

 
sridhar panini
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is my requirement:

I have an input page and I enter the required fields which will query the Database and fetch the ResultSet. Using this ResultSet I created a DataModel i.e., ListDataModel and displayed this data on the result screen.

Here is the tricky part for me.
For each row displayed, I have a LINK for each record and when I Click the record I want to see selected fields of that row in a NEW Page.
I get redirected to a new page thats not a problem. I am not sure how to select that particular row in that Model.

Any ideas on this.
let me know.
 
Padma Lalwani
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I understand correctly your ListDataModel is a list, allowing sequential traversal. But you need to access your objects by a key value, so in addition to storing it in a list, you would need to save a reference to your objects as the value in a key-value data structure like a Hashtable, and a unique ID as key. The key would be also be the unique id passed by the link, the user has clicked on. And also you would not duplicate the objects but only save the same reference in two different DataModels

Padma
 
ansar basha
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need a binding to the dataTable

<h:dataTable styleClass="dataTable" id="list" value="#{PostCodeBean.postCodeList}" var="plist" rows="10"
binding="#{PostCodeBean.postCodeTable}">

Java Code:
private UIData postCodeTable;
<- setter and getter for this variable ->

then you can access the selected row with:
Object selectedObject = (Object) postCodeTable.getRowData();
 
sridhar panini
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did the above binding and created the setXX() and getXX() methods and when I click the commandLink and get the Row It always gives me the last record in that page.

It does not give me the row I am click on.

Please let me know if there is a way to get the current row.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
kittu kittu

Please review our Naming Policy and adjust your display name accordingly. You can change your display name by clicking here.

Thank you.
 
sridhar panini
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey,

Any idea on why the getRowData() returns the last record instead of selected row.
any help would be really appreciated.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sridhar (formally kittu kittu)

You were actually closer the first time around. Your display name must be made up of a first and last name. We know not all cultures follow this naming convention and while we prefer real names, but if you don't have a first and last name (surname), as long as it sounds real, you can make one up. For example, you could go by sridhar kittu or kittu sridhar.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!