• Post Reply Bookmark Topic Watch Topic
  • New Topic

SelectOneRadio from a Stringtype List. No Selection possible

 
Tuenay Oezcan
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

i am struggling with the problem that my radio buttons, wich are dynamically created are intially checked.

JSF:



The ouptut on the application is right. Problems are:

- All radio buttons are checked initally
- No further selection is possible

I would appreciate any help. Thank you guys !
 
Tim Holloway
Bartender
Posts: 18408
58
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What? "Controller" and not "Kontroller"? But JSF backing beans are not Controllers. They are Models.

As a general rule, I discourage the use of ui:repeat and other logic-like constructs. If you have a tabular display, use the dataTable tag, instead. However, ui:repeat does have uses, such as when you want to arrange your collection horizontally rather than vertically.

There are several basic items that need to be addressed.

1. f:selectItem needs both an itemLabel and and itemValue. The itemValue is the value that will be posted to the radio control's target.

2. You must name a target in the h:selectOneRadio that will receive the selected value - and conversely be used to set the displayed selection. This is the "value=" attribute of the selectOneRadio tag element.

3. Normally when you nest iterative and tabular constructs, the inner construct's "value" attribute references the outer construct's "var" value.

I think before doing anything this ambitious, you need to study up on a few basics of JSF.

 
Tuenay Oezcan
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tim! Thanks for the reply. Yes my bean class is called controller, since my model class is a entity class which holds everything from my database. Can you please post an example of how to use select one radio buttons in a data table. Its just weird because my lists are correctly executed. The only problem is to save the selected value in a arrayList, which should be possible in a select one radio value....I changed my code to the following:



Is there any way to put an index on the <h:selectOneRadio id="radio" value="#{fragebogenController.antwortUser}" list antwortUser?

You are totally right about the basics i am actually sitting here (for 4 weeks now) with numerous jsf for dummies book but since my user requirements include such a problem i can`t seem to solve it with the basics ;)

Thank you very much!!!


 
Tim Holloway
Bartender
Posts: 18408
58
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do not mistake the UI Model for the Business or Persistence Models. JSF backing beans are UI Models. In JSF, the Controllers are pre-supplied by the framework, not coded as application functions.

You do not have an "index" for a selectOne control. Instead, the value corresponding to the SelectItem is injected into the control's "value=" property. Conversely, if the model sets this property, the next time the View is displayed, the button whose selectItem value matches will be displayed selected. A Validation exception occurs if no selectItem value can be found that matched.

It is good practice to include the "id=" attribute on all input controls. Some JSF error messages display control IDs, and the ones that are synthesized by default when no explicit ID is supplied are usually neither predictable nor helpful.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!