• Post Reply Bookmark Topic Watch Topic
  • New Topic

Activating selectoneradio buttons on page load  RSS feed

 
Randy Maddocks
Ranch Hand
Posts: 148
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I am not sure if this is actually a primefaces issue, or java related, so hopefully I have chosen the right forum (if not, my apologies and it may be moved to the appropriate forum).

Conceptually this should be simple to do, but for the life of me I cannot figure out how to do it. In a nutshell, I have a selectoneradio component on a primefaces form which contains 4 radio buttons. When a user clicks any of the 4 radio buttons another set of radio buttons is displayed. Then, depending on which radio button is clicked in the 2nd set, a 3rd set of radio buttons is displayed. Once the user clicks the appropriate buttons and enters all other information on the form and then saves it, the data is written to an Oracle database, with the value storing the final radio button that was clicked being written as an integer in the database.

When the record is retrieved from the database the data is populated in the primefaces form with the same layout. The 2 or 3 sets of radio buttons selected by the user before saving the form are supposed to be shown as being activated (or selected). The only thing working so far is I have the correct sets of radio buttons showing, but the ones that are supposed to be pre-selected are not selected.

I am using NetBeans 8.0, JDK 1.7, JBoss EAP 6.2, Primefaces 5.0, Hibernate 3.0

Here is a snippet of the code that I have been debugging to try and figure this out (if more code needs to be provided I can do so):

.xhtml form:



backing bean


I hope this code, and my explanation, makes sense. Thank you!
 
Tim Holloway
Bartender
Posts: 18715
71
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rant #1: I don't care WHAT NetBeans generates. Backing beans are not Controllers. They are Models.

Rant #2: This is bad syntax: #{foreignPartyController.onEntityFfiTypeRadioButtonClick()}. Action and listener methods in EL are supposed to be method references, not method calls, so the "()" should be omitted.

OK. This sounds like a variant of the classic 3-stage dropdown list a la country/State/City. Very common and not too difficult, once you know how to do it.

You can make the successive sets of buttons appear by attaching a "value change" event listener to the preceding level's buttons and having the AJAX server-side method set a "display me" boolean value. The event listener should then do a re-render of the child control, where the child control's "rendered=" attribute is the value of the "display me" boolean property. Use one "display me" property per hide/show level.

A radio button gets selected when the associated backing bean property for the button set (selectOneRadio control) has a value that is equal to that particular button's SelectItem value. This selection will be updated whenever the button set is re-rendered, whether it's on initial page load or as a result of an AJAX re-render that includes the ID of the button set.
 
Randy Maddocks
Ranch Hand
Posts: 148
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tim,

Rant away - I don't learn otherwise!! :thumbup:


Rant #2: This is bad syntax: #{foreignPartyController.onEntityFfiTypeRadioButtonClick()}. Action and listener methods in EL are supposed to be method references, not method calls, so the "()" should be omitted.


My bad - the parentheses should not be there! That has been corrected, and thanks for bringing that to my attention.

Also, thanks for the explanation, I will try what you have suggested. Thanks again Tim!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!