ラジオボタンコンポーネントの値に基づいて入力テキストコンポーネントを検証しようとしていますが、がスローされ、そのNullPointerException
理由がわかりません。
ビューは次のとおりです。
<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>
バリデーターは次のとおりです。
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);
}
}
例外は次のとおりです。
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