• Post Reply Bookmark Topic Watch Topic
  • New Topic

Datascroller loses values randomly when changing pages

 
Jason O'Brien
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

So I have a rich:Datascroller with a rich:DataTable. One of the columns has a selectOneRadioButton with the values "approve", "decline" and "none". When the page loads all the rows have the value set to "none by default". At the bottom of the page is a group of buttons, one of which is "approve all" which sets the value for that column to "approve" for each and every row.

My problem come in when I change to next page from page 1, the values for this column on pages other than page 1 are set to null and hence none of the radio buttons are selected. This does not happen every time, it happens randomly. I found advice online to try and set the ajaxSingle attribute of the datascroller to false but this has not helped.

Any advice would be greatly appreciated.

Thanks,
Jason
 
Jason O'Brien
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I should probably also mention that I cannot replicate this issue when working on my local server however when deployed to the application server I experience the problem.
 
Tim Holloway
Bartender
Posts: 18470
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As a general UI rule - not just for Java - you should not use radiobuttons to make multiple selections. A radio button is for when you want to allow one and only one selection to be made. They get their name from the old-time auto radios which had buttons that you would press in to select a station (unlike modern-day presets, where the button pops right back up again). When you pressed a button, any previously-depressed button would pop out.

For multiple selections, therefore, use checkboxes. Also note that because radio buttons are supposed to be 1-of-many selections, the radiobutton control value must be an object that can hold as many different values as there are buttons in the set, whereas checkboxes only have one value object with a value of true (selected) or false (not selected).

The rendering and processing of a dataTable is based on its DataModel. If you want selections to persist as you page through a dataset, therefore, you need a column in that DataModel that holds the selection state for each row being displayed.

Unfortunately, most DBMS's do not have a native boolean data type, and the Checkbox control won't work with any other data type, so you have to adjust the DataModel's wrapped data set to provide one. Basically, if you're using an ORM class, front it with a façade class object that presents the boolean columns in true boolean form instead of Y/N, 0/1, or whatever it actually uses.

If the selection state is not something that you actually keep in the database, the same architecture still applies, you just don't have the extra logic in the façade to convert the checkbox boolean state from/to the corresponding database column (since there isn't a corresponding column).
 
Jason O'Brien
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Tim. Your reply was very informative. I obviously did not word my initial post very well but there are three options to select with the radio buttons but as you say only one option per row may be selected.

I have resolved the problem thankfully. The ajaxSingle attribute I mentioned above did the trick. The build just did not compile correctly the first time around.

Thanks again!
 
Tim Holloway
Bartender
Posts: 18470
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You probably worded your first post well enough. It's just I have a bad habit of missing stuff on the first reading. I catch up eventually, though.
 
Gravity is a harsh mistress. But this tiny ad is pretty easy to deal with:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!