I have a / group of radio buttons , and a CommandButton
Two cases
1)When one of the button is clicked + The command Button is clicked, I should display some other section(say a DIV) and the execution stops. means, The Command Button should not submit the form to the server
1)When NONE of the button is clicked + The command Button is clicked,I should submit the form to the server and display a Faces Message that he has not selected anything.
I don’t want to do this alert as a JavaScript popup.Suggestions are welcome.
Yes, that’s possible with a little help of JavaScript. Easiest would be to give the ID of the section div elements as radio button value and then loop through all radio buttons and show/hide the element based on the button’s
checkedstate. At end you should let the JS function returnfalsewhen any button is checked so that the button’s default action won’t be invoked and the form won’t be submitted to the server.Here’s a kickoff example:
with this CSS
and this JS
and JSF bean (we of course assume that this action will only be invoked if none is selected).