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 8381077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T16:37:01+00:00 2026-06-09T16:37:01+00:00

I have three radio buttons, an inputText and a submit button. I only want

  • 0

I have three radio buttons, an inputText and a submit button. I only want to validate the input text on submit when a certain radio is selected. So I have

<h:inputText validator="#{myBean.validateNumber}" ... />

And in my bean I have

 public void validateNumber(FacesContext context, UIComponent component,
                Object value) throws ValidatorException{
      if(selectedRadio.equals("Some Value"){
           validate(selectedText);
      }
 }

 public void validate(String number){
      if (number != null && !number.isEmpty()) {
        try {
            Integer.parseInt(number);
        } catch (NumberFormatException ex) {
            throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR,
                "Error", "Not a number."));
        }
      } else {
        throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR,
                "Error", "Value is required."));
      }
 }

The one thing that make this not work is that when I submit, validateNumber(...) runs before my setter method for the radio button setSelectedRadio(String selectedRadio). Therefore causing this statements

 if(selectedRadio.equals("Some Value"){
       validate(selectedText);
 }

to not execute correctly. Any idea on how to get around this problem?

  • 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-06-09T16:37:02+00:00Added an answer on June 9, 2026 at 4:37 pm

    The selectedRadio is as being a model value only updated during update model values phase, which is after the validations phase. That’s why it’s still the initial model value while you’re trying to examine it.

    You’d have to grab it from either the request parameter map (which is the raw submitted value), or the UIInput reference, so that you can get either the submitted value by getSubmittedValue() or the converted/validated value by getValue().

    So,

    String selectedRadio = externalContext.getRequestParameterMap().get("formId:radioId");
    

    or

    UIInput radio = (UIInput) viewRoot.findComponent("formId:radioId"); // Could if necessary be passed as component attribute.
    String submittedValue = radio.getSubmittedValue(); // Only if radio component is positioned after input text, otherwise it's null if successfully converted/validated.
    // or
    String convertedAndValidatedValue = radio.getValue(); // Only if radio component is positioned before input text, otherwise it's the initial model value.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my page I have three radio buttons and I want to checked the
I have a group of three radio buttons. Depending on which radio button is
I have three radio buttons and a textfield generated by drupal. What I want
I have three radio buttons <input id=RadioJ type=radio name=grp1 class=abc /> <input id=FaroK type=radio
I want to have three radio buttons, two on one line and one on
I have a form with three radio button options, and a submit button (no
I have three radio buttons like this: <input type=radio name=P_1 value=1>Yes</input> <input type=radio name=P_1
I have three radio buttons with same name and different values.When I click the
I have three radio buttons, let's call them R1, R2 and R3. (R1 is
I have 3 file uploads and three radio buttons associated with them. All radio

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.