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

  • Home
  • SEARCH
  • 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 9003579
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:43:47+00:00 2026-06-16T00:43:47+00:00

I am trying to validate an input text component based on the value of

  • 0

I am trying to validate an input text component based on the value of a radio button component, however it throws a NullPointerException and I don’t understand why.

Here’s the view:

<h:form id="formId">
    <p:inputText validator="#{searchBean.validate}" id="name"
        required="true" requiredMessage="should contain only characters">
        <f:validateRegex pattern="[a-zA-Z]*" />
        <f:validator validatorId="inputValidator" />
    </p:inputText>
    <p:selectOneRadio value="#{searchBean.searchForm.selectedRadio}" id="customRadio">
        <f:selectItem itemLabel="city" itemValue="1" />
        <f:selectItem itemLabel="zipcode" itemValue="2" />
        <f:selectItem itemLabel="state" itemValue="3" />
    </p:selectOneRadio>
    <p:commandButton value="Search" action="results.jsf" />
</h:form>

Here’s the validator:

public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
    UIViewRoot ui = new UIViewRoot();
    UIInput radio = (UIInput) ui.findComponent("formId:customRadio");
    boolean convertedAndValidatedValue = (Boolean) radio.getValue(); // This line is throwing the exception.
    System.out.println("Validate"+convertedAndValidatedValue);

    if (searchForm.selectedRadio.equals("city")) {
        validateForCity(convertedAndValidatedValue);
    } else if (searchForm.selectedRadio.equals("zipcode")) {
        validateForZipcode(convertedAndValidatedValue);
    } else {
        validateForState(convertedAndValidatedValue);
    }
}

Here’s the exception:

javax.faces.FacesException
    at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:80)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:97)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:114)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:308)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:987)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:579)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:309)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    at java.lang.Thread.run(Thread.java:679) 
Caused by: java.lang.NullPointerException
    at com.placessearch.action.SearchBean.validate(SearchBean.java:76)
    at javax.faces.component.UIInput.validateValue(UIInput.java:1142)
    at javax.faces.component.UIInput.validate(UIInput.java:960)
    at javax.faces.component.UIInput.executeValidate(UIInput.java:1204)
    at javax.faces.component.UIInput.processValidators(UIInput.java:693)
    at javax.faces.component.UIForm.processValidators(UIForm.java:240)
    at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1081)
    at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1081)
    at javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:1159)
    at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:72) 
    ... 19 more
  • 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-16T00:43:48+00:00Added an answer on June 16, 2026 at 12:43 am

    JSF components are converted and validated in the order as they appear in the component tree. Your validator is attached to an input text component which appears before the radio button component. However, you’re trying to access the converted and validated value of the radio button component, while it is not been converted and validated at that point yet.

    boolean convertedAndValidatedValue = (Boolean) radio.getValue();
    

    It would only return null which you’re in turn trying to autobox to boolean which would only cause NullPointerException.

    You need to get the submitted value instead. Please note that the item values which you’re specifying there are absolutely not booleans. It are numbers. Also note that the submitted value is always String (simply because that’s exactly the type which request.getParameter() returns and also because at this moment it’s not been converted by JSF/EL yet).

    String submittedRadioValue = (String) radio.getSubmittedValue();
    
    if (submittedRadioValue != null) {
        int convertedRadioValue = Integer.valueOf(submittedRadioValue);
        // ...
    }
    

    Update: another cause which I overlooked due to its unexpected nature is the following:

    UIViewRoot ui = new UIViewRoot();
    

    This is definitely also not right. You’re supposed to retrieve the current one from the faces context instead of manually creating a completely empty one.

    UIViewRoot ui = context.getViewRoot();
    

    Otherwise radio would still be null and thus be another potential cause of the NullPointerException.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way to validate a field text input based on radio button
I am trying to validate a text input when it loses focus. I would
I’m trying to validate input by using egrep and regex.Here is the line from
I am trying to validate a text input. I have noticed though that it
I'm trying to validate the input of multiple text boxes (i.e. they should be
I'm trying to find a way to validate a text input on key press,
i am trying to validate my form fields calling the input text ids, but
I am trying to validate the input from the users with regular expressions here
I'm trying to validate user input on a text parameter using a VB function.
I am trying the validate the text input of an entry. entry $w.e -validate

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.