here I am not using radio button groups , I am using to different radiobuttons , so I want to validate the required fields of these radiobuttons dynamically.
Just for an example , say initially two radiobuttons required fields should be true , then when user click the first radio(radio1) the required fields of these 2 radios should be false .I want to do it like that way.
**** I am using valueChangeListener for radio buttons, is there any other way out to solve this problem ?
They're called "radio buttons" because back before electronic presets, automobile radios had a bank of mechanical buttons used to select preset stations. These buttons were designed so that when you pushed one button in, whatever button was previously pushed in would pop out. In other words, you couldn't push multiple buttons - only one selection was allowed at a time.
This is different from a check box. Each check box can stand by itself, and only cares what state other controls are in if you code explict logic to link them.
Visually, the radio button is usually circular and the check box is usually square, but it's the different functionality that really matters. Functionally, one check box can do the work of 2 radio buttons, since a properly functioning radio button bank has exactly one and only one button switched on at any time - and should never have them all switched off unless the bank is completely disabled. Radio buttons are more appropriate when there are more than 2 possible states, although some GUIs also have provision for a tri-state checkbox.
Since I don't have a completely accurate picture of what you're attempting to control, I can't give a definitive answer, but it's more common when mixing controls which affect other controls that the affected controls are disabled, not "validated". JSF provides the "disabled="true"" attribute for that purpose.
Validators don't appear to be appropriate here. What you'd typically do is make the controlling buttons have "immedate="true"" actions and set the disabled properties in the controlling button action processors. For better polish, you could use an AJAX framework like RichFaces so that instead of re-rendering the entire page, only the affected controls are updated on the page display.
Sometimes the only way things ever got fixed is because people became uncomfortable.
Actually I am creating two different radio buttons (not any button group), say radio1 and radio2.When I am selecting radio1's action the page will render & show some text fields below the radio1 but above the radio2 .When I am clicking the radio2 some text fields will appear below the radio2.This is my exact functionality .For that reason I am using two different radio buttons.But the problem is coming when I want to implement the validation .I want to validate two radio buttons.If user is not selecting any one of them then JSF will show the validation message .Initially radio1 and radio2 both have same required fields to true .I can do it in my backing bean .Suppose user is selecting radio1 then those two required fields should be false for radio1 and radio2. For radio1 and radio2's action purpose I am using valueChangeListener.
When user clicking the radio1 the radio2's value should be null & exactly opposite for radio2.For that reason am using a small code something like this in my valueChangeListener :
My radio1 and radio2's check un-check functionality is going perfect , but I am not able to validate both radio buttons.If I commenting out all those PHASE related code then only it is working fine .But at the same time my check un-check functionality is not working.
Personally I would change your implementation. If the user should only have radio1 or radio2 set, then these should be part of a group. Then you simply validate that group.
As Tim said, "radio buttons" are called just that because of old radios. When one station button was pressed, the current station button would pop out; only one station was allowed at a time (unless you managed to press two or three buttons at once and confuse the radio, but then you Dad would shout at you).
This is exactly what you want - one and only one set.
Hi Jason Irwin ,
Thanks for your reply , but the problem is I can not use one radio button group , because I have to render when radio1 is clicked & show some text fields in between these two radio buttons, same when I will click the radio2 I have to show some text field below the radio2 , but at the same time those text fields in between radio1 and radio2 will get disappear.
This is my functionality , is it possible to render between two radio buttons ?