Win a copy of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams this week in the Reactive Progamming forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

Render radio buttons or checkboxes when a selectOneMenu option is clicked

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to render radio buttons or checkboxes when the user selects one of the options from a select one menu. Also, when the user selects one of the options and the radio/checkboxes appear, the user must be able to insert as many radio buttons or checkboxes as he/she wants; like Google forms when you are creating a form.

How could I do it?
 
Saloon Keeper
Posts: 21127
131
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSF is based on the Model/View/Controller architecture. For collections of controls, you simply need a corresponding model.

A selectOneRadio control is a single element with multiple possible selections, only one of which may be selected at a time. In that sense, it's the same thing as the selectOneMenu dropdown list control, just with different control graphics. In both cases, your model is a collection of SelectItem sub-model objects. A SelectItem defines a displayed label and its corresponding value. You can create this collection for a given control by adding one or more "h:selectItem" and/or "h"selectItems" (note plural) child elements. Both operate the same, except that the selectItems element maps to an ordered collection (List or array) of SelectItems, where selectItem (singular) is backed by a single SelectItem object. You can also do brute-force SelectItem creation using the "itemLabel" and "itemValue" attributes, but that hard-codes the structure onto the View Template and you want something more flexible.

Here's how you can combine single and collection SelectItems using a selectOneMenu control as an example:


This displays a list with the "--- Make a selection ---" item set if no selection has been made yet. SInce "required=true" is set on the control, the form will not be accepted for processing until one of the items in selectItems list is chosen.

You can do the same thing using the "selectManyCheckbox" control.

To achieve what you want, add an f:ajax sub-element to the control that creates the list of possible selections and have it specify a "render="attribute value(s) for the ids of the checkbox and radio button control(s) you want updated. The Ajax listener can create the updated selection models, and the re-rendering option will then refresh the display showing those model values.
 
Don't count your weasels before they've popped. And now for a mulberry bush related tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!