• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to select row via code an item on a coretable, uixcollection or uixtable component in java?  RSS feed

 
Winston Liek
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how to select row via code an item on a coretable, uixcollection or uixtable component in java?

Sorry guys, I'm newbie in JSF. I have an af:table and has tableselectone component (this means for every row, user can select a row by having a radio button per row) however, I want to select/tick the radio button of the second item (if any) on the row via code. Can someone tel if is this feasible?

Thanks!
 
Tim Holloway
Bartender
Posts: 18715
71
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure what any of that means. I'm not even sure what JSF extension framework that's for.

I can tell you that the core JSF provides a model wrapper class called DataModel that can decorate a generic array or sequential collection (such as List) with the additional context needed for the action method to know which row you clicked on in a dataTable and this serves as the basis for many of the third-party dataTable extensions.

Some of the extensions also provide multi-select features, but for their proper use, you'd have to read the extension-specific documentation.

A crude but effective way to mark multiple rows for attention would be to provide a boolean property in the table's model data that backed a checkbox in the table row template.

Radio buttons, on the other hand, aren't suitable out of the box for single-row selection, since JSF elements cannot overlap, and you'd have a conflict with the row definitions containing slices of the radio button. You can get around this by providing single-element radio buttons (or suitable CSS images) and some client-side javascript to enforce the single-selection option.
 
Winston Liek
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply. Here's the current system. I hope someone could give their suggestions.

I have a page that has a text field that accepts a number and a table with preloaded data binded in a variable (When I debugged and inspected the content of the variable, the variable has CoreTable and ArrayList as Data model)

What I want is that when a user typed a number on the text field and clicked 'OK' button, it will auto highlight/select the row using the user inputted number as row index inside the table (forget about number out of range in the rows; I just want to know how to do the autoselecting of rows in a table backend/via java code). I tried using table.setRow(num) where num is the user input and table is the CoreTable associated with the table but it's not working
 
Tim Holloway
Bartender
Posts: 18715
71
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry about the delay, but I didn't really know what to do here.

There is no such thing technically as a "selectable" table row in HTML, which is what JSF is usually rendered to. What we call "row selection" means one of 3 things:

1. You fire a submit control embedded within a row in a table. That row then counts as the "selected" row, and it's available from the DataModel via getRowData()/getRowIndex()

2. You add a set of selection controls (typically checkboxes) to the rows of a table, and when the form containing the table is submitted, the action logic scans the table's model, looking for the rows where the checkbox had been selected (that is, the backing model property value is "true").

3. You use an extension tagset that supports Excel-style tables where clicking on one or more rows or ranges causes the table to visually highlight, courtesy of client-side logic that the tag generates. When this sort of extended table is selected, there's generally some sort of model property that can receive a collection of indicators as to which rows were highlighted (selected). The format and details of that vary with the extension tagset, since this is not a feature supported by coreJSF.

To programmatically select table rows, for option 2 you'd simply set the selection property values to "true" in order to cause the boxes to appear checked when JSF re-rendered it.

To programmatically select table rows for option 3, you'd construct or update a selection object and present it to the "getter" of the table multi-selection property. And again, the details depend on the extension tag that you are using.

You cannot programmatically select option 1, since it has no visual counterpart - it's just the consequence of clicking on a row.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!