PropertyNotFoundException Target Unreachable, identifier ‘patientBean’ resolved to null
I have been trying to get a simple @ManagedBean example working without the use of faces-config.xml. My bean is fairly simple:
@ManagedBean(name = "patientBean") @SessionScoped public class PatientBean { Integer randomInt = null; Integer userNumber = null; String response = "test"; private long maximum = 10; private long minimum = 0;
But when I try to access this through a simple facelet page such as:
<h:inputText id="userNo" value="#{patientBean.userNumber}">
I get this error complainign about the managed bean target:
javax.el.PropertyNotFoundException: /greeting.xhtml @23,55 value="#{patientBean.userNumber}": Target Unreachable, identifier 'patientBean' resolved to null at com.sun.faces.facelets.el.TagValueExpression.getType(TagValueExpression.java:100) at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getConvertedValue(HtmlBasicInputRenderer.java:95) at javax.faces.component.UIInput.getConvertedValue(UIInput.java:1030) at javax.faces.component.UIInput.validate(UIInput.java:960) at javax.faces.component.UIInput.executeValidate(UIInput.java:1233) at javax.faces.component.UIInput.processValidators(UIInput.java:698) at javax.faces.component.UIForm.processValidators(UIForm.java:253) at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1214) at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1214) at javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:1172) at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:76) at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118) at javax.faces.webapp.FacesServlet.service(FacesServlet.java:395) at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1534) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175) at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595) at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:98) at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:91) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:162) at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:326) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:227) at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:170) at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:822) at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:719) at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1013) at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:225) at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137) at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104) at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90) at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79) at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54) at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59) at com.sun.grizzly.ContextTask.run(ContextTask.java:71) at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532) at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513) at java.lang.Thread.run(Thread.java:662)
While I have searched the net looking for the answer without luck, I stubled upon the issue. In the maven war plugin, there was an attribute to <archiveClasses>true</archiveClasses> which creates a jar of all classes and adds that jar to the WEB-INF/lib directory.
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>${plugin-war-version}</version> <configuration> <archive> <addMavenDescriptor>false</addMavenDescriptor> </archive> <strong><archiveClasses>true</archiveClasses></strong> <failOnMissingWebXml>false</failOnMissingWebXml> </configuration> </plugin>
This causes the bean to not be found unless I mapped it directly into the faces-config.xml:
<managed-bean> <managed-bean-name>patientBean</managed-bean-name> <managed-bean-class>com.baselogic.chapter03.web.PatientBean</managed-bean-class> <managed-bean-scope>session</managed-bean-scope> </managed-bean>
setting this to false in the maven-war-plugin allowed me to remove the faces-config.xml entry.
<archiveClasses>false</archiveClasses>
Recent Comments