• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

validation in radio buttons

 
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi every body ,

Is it possible validate to different radio button groups ?

Here is my JSF code :




Here , when I am, clicking the Radio1 / Radio2 the validation of Radio2/Radio1 should be false .
Is it possible assiging validation dynamically ?

Thanks,
S
 
Saloon Keeper
Posts: 28584
211
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't know how you mean validation where there's only 2 possible states.

As far as having button1 turn off button 2 and vice versa,, that's done automatically for buttons in the same group.
 
S Majumder
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Tim Holloway ,
Thanks for your reply ,

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 ?


regards,
S
 
Tim Holloway
Saloon Keeper
Posts: 28584
211
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

In order to provide better interactivity, it's common to use JavaScript to do client-side control of things of this nature, although a well-written app will also understand that JavaScript might be disabled and provide server-side support as a backup (and to ensure that no one short-circuits the intent).

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.
 
S Majumder
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks again ,

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.

This is my problem.

If you need more explanation please let me know .

regards,
S
 
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
S Majumder
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ?

regards,
S
 
Tim Holloway
Saloon Keeper
Posts: 28584
211
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

s begri wrote:
This is my functionality , is it possible to render between two radio buttons ?

regards,
S



Certainly, although please do so carefully, so as to avoid confusing users. The general convention is to indent the dependent items.

The radio button functionality is based on them all sharing a common button group ID, so physical placement doesn't matter.
 
S Majumder
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could you please help me , how could I do that ?
reply
    Bookmark Topic Watch Topic
  • New Topic