Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 886179
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T13:01:40+00:00 2026-05-15T13:01:40+00:00

I have a / group of radio buttons , and a CommandButton Two cases

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T13:01:41+00:00Added an answer on May 15, 2026 at 1:01 pm

    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 checked state. At end you should let the JS function return false when 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:

    <h:form id="form">
        <h:selectOneRadio id="radio">
            <f:selectItem itemValue="section1" itemLabel="Show section1" />
            <f:selectItem itemValue="section2" itemLabel="Show section2" />
            <f:selectItem itemValue="section3" itemLabel="Show section3" />
        </h:selectOneRadio>
        <h:commandButton id="button" value="show section" 
            action="#{bean.submit}" onclick="return showSection(this.form)" />
        <h:messages />
    </h:form>
    <h:panelGroup layout="block" id="section1" class="section">section1</h:panelGroup>
    <h:panelGroup layout="block" id="section2" class="section">section2</h:panelGroup>
    <h:panelGroup layout="block" id="section3" class="section">section3</h:panelGroup>
    

    with this CSS

    .section {
        display: none;
    }
    

    and this JS

    function showSection(form) {
        var radiobuttons = form['form:radio'];
        var selected = false;
        for (var i = 0; i < radiobuttons.length; i++) {
            var radiobutton = radiobuttons[i];
            var section = document.getElementById(radiobutton.value);
            if (radiobutton.checked) {
                section.style.display = 'block';
                selected = true;
            } else {
                section.style.display = 'none';
            }
        }
        return !selected; // Submits to server if none is selected.
    }
    

    and JSF bean (we of course assume that this action will only be invoked if none is selected).

    public void submit() {
        FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Please select!"));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have got a group of radio buttons that when clicked need to display
I have this group of radio buttons in which each of individual button has
I have a group of three radio buttons. Depending on which radio button is
I have a html form which contains group of radio buttons. When one of
i have a form with a radio button group(6 radio buttons), id's are r1,r2,r3,r4,r5,r6
I have group of radio buttons that I want to uncheck after an AJAX
I have group of radio buttons, each group ranges from 5 - 27 radiobuttons.
I have a group of radio buttons in my Swing application that have a
Hai, I have a group of radio buttons, i could able to pick the
I have a group of radio buttons in a form, I need to pass

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.