views:

472

answers:

2

Hi all,

While accessing a property from a sub class in JSF, it fails with the error below:

javax.el.PropertyNotFoundException: /grouptable/Create.xhtml @19,281 value="#{grouptableController.selected.grouptablePK.groupid}": Target Unreachable, 'null' returned null
at com.sun.faces.facelets.el.TagValueExpression.getType(TagValueExpression.java:93)
at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getConvertedValue(HtmlBasicInputRenderer.java:95)
at javax.faces.component.UIInput.getConvertedValue(UIInput.java:1008)
at javax.faces.component.UIInput.validate(UIInput.java:934)
at javax.faces.component.UIInput.executeValidate(UIInput.java:1189)
at javax.faces.component.UIInput.processValidators(UIInput.java:691)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1080)
at javax.faces.component.UIForm.processValidators(UIForm.java:243)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1080)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1080)
at javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:1180)
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:312)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1523)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:279)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:188)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:641)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:97)
at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:85)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:185)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:332)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:233)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:165)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:791)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:693)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:954)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:170)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:135)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:102)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:88)
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:76)
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:53)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:57)
at com.sun.grizzly.ContextTask.run(ContextTask.java:69)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:330)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:309)
at java.lang.Thread.run(Thread.java:637)

Has anyone see this before? Please help. I am using glassfish v3.

A: 

If you're having a hard time interpreting the error, what it means is that on your facelets page, it can't figure out what you mean by:

#{grouptableController.selected.grouptablePK.groupid}

Hope this helps.

Jon
+1  A: 
value="#{grouptableController.selected.grouptablePK.groupid}": 
Target Unreachable, 'null'

This basically means that one of the nested properties is null. In this context, it can be can be either selected or grouptablePK which has returned null. Those shouldn't be null whenever JSF needs to set the groupid property.

You need to preinstantiate those nested objects/beans yourself. JSF/EL won't do that for you.

Thus, instead of

public class ParentBean {
    private ChildBean childBean;
}

you need to do

public class ParentBean {
    private ChildBean childBean = new ChildBean();
}

or

public class ParentBean {
    private ChildBean childBean;
    public ParentBean() {
        this.childBean = new ChildBean();
    }
}

Alternatively, if the ChildBean is also a managed bean, or can be one, then you can also make use of managed property injection in faces-config.xml:

<managed-bean>
    <managed-bean-name>parentBean</managed-bean-name>
    <managed-bean-class>com.example.ParentBean</managed-bean-class>
    <managed-bean-scope>request</managed-bean-scope>
    <managed-property>
        <property-name>childBean</property-name>
        <value>#{childBean}</value>
    </managed-property>
</managed-bean>
<managed-bean>
    <managed-bean-name>childBean</managed-bean-name>
    <managed-bean-class>com.example.ChildBean</managed-bean-class>
    <managed-bean-scope>request</managed-bean-scope>
</managed-bean>
BalusC
I have the same situation BalusC. `#{document.selectedDrawing.name} Target Unreachable, "null"`. `document` is the managed bean. `Drawing selectedDrawing` where `Drawing` is the entity class. What I dont understand is that, it display the name of the selected drawing correctly. But then when I click to the `commandButton` to link to somewhere else, it pop that error. I dont understand if it already display the correct value, then how `selectedDrawing` be `null`. I read your post, and try `selectedDrawing = new Drawing()`, it fix it, but created another drawing inside my database.
Harry Pham
@Harry: Lazy loading issue in your persistence layer?
BalusC
In my managed bean, I used lazy loading to load all the `Drawing` to a `list<Drawing>`. I dont think I use any in my session bean
Harry Pham
I changed lazy loading to inject `@PostConstruct` to `public void init()`. And it still does not fix it. If u can help me a bit, I would greatly appreciated
Harry Pham