wood burning stoves*
The moose likes JSF and the fly likes How can I display this using SelectOneRadio? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "How can I display this using SelectOneRadio?" Watch "How can I display this using SelectOneRadio?" New topic
Author

How can I display this using SelectOneRadio?

Rob Micah
Ranch Hand

Joined: Aug 30, 2011
Posts: 94
What I need is a layout like this:



Notice that it has 3 elements grouped together. When I use the SelectOneRadio I can't get it to render anything more than 1 input element. The following produces all elements before a table element with the table element containing all the radio buttons.



So how can I do this in JSF?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16019
    
  20

I just reviewed the Oracle docs. They're awful.

The selectOneRadio generates an HTML table (not an HTML list). The elements within the table are rendered from the f:selectItem child elements.

Members of the "f" tag library do not generate HTML. They may contain data that is used by container elements as part of the container rendering process, as is true in this case, but they don't directly render anything. You'll notice that there are no rendering attributes for selectItem except for the "disabled" attribute.

Simply jamming HTML into the body of the JSF tag won't work. I don't recommend mixing JSF and HTML to begin with, but in this case, the tag is so abstract relative to what gets generated that there's simply no meaningful place to put stuff like that.

There may be SOME hope, though. Try this:



The "escape=false" attribute allows you to use raw HTML in the itemLabel. Unfortunately, this is XML, so you must use the entity escapes or it won't parse properly. Don't forget the ";" that terminates each entity.


Customer surveys are for companies who didn't pay proper attention to begin with.
Rob Micah
Ranch Hand

Joined: Aug 30, 2011
Posts: 94
Yeah this is awful all the way around. Really I don't necessarily have to have a list element I just need a containing box for the radio button and 2 other elements with it. Or even a table that had a row with those 3 elements in the same row might work.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16019
    
  20

The hard part is getting the radio action where selecting one pops up the others.

There are 2 ways you could deal with this.

1. Apply CSS to set the image elements on each HTML radiobutton element under that control.

2. Render a panelGrid and checkbox controls with Javascript attached to do the 'pop up' function and CSS to provide alternative (radiobutton-shaped) checkbox images.
Rob Micah
Ranch Hand

Joined: Aug 30, 2011
Posts: 94
I think I found the best way. I used a h:inputHidden element within a <div> with an id on it. Then I created the radio buttons and their layouts myself. I hooked some javascript (jQuery) onto the change event of the radios and changed the value of the hidden element to match the radio in the event handler. It works so far and is much smaller and cleaner. Here's the code:

 
jQuery in Action, 2nd edition
 
subject: How can I display this using SelectOneRadio?