I have a class Person and a class Name. Name contains two Strings firstName and lastName. Person contains a Name object as well as some additional info. How can I access the firstName and lastName attributes within person using JSF EL. I am using JSF 2.0 with annotations.
I have a registration page where I am creating a new Person. I have a managed bean called PersonBean with an instance of a Person. I am attempting to set the first in my xhtml page using the following tag: #{personBean.person.name.firstName}. This gives me a null error.
The exact code:
<h:inputText label="First Name" id="fname" value="#{personBean.user.name.firstName}"
required="true"/>
The exact error message: "value="#{personBean.user.name.firstName}": Target Unreachable, 'null' returned null".
I believe this error stems from the fact that I am trying to call getters/setters from the Name object when the Person object is not yet instantiated.
Thanks
I think you have given your own answer: “the Person object is not yet instantiated” JSF will not create objects for you unless they are managed beans. So you should instantiate the
Personobject before you access the name. You could do it when the bean is instantiated or during the user action that causes the component to be shown.You probably do not want to make the
Personobject a managed bean, but you could do that and then have it injected into thepersonBean: http://balusc.blogspot.com/2006/06/communication-in-jsf.html#InjectingManagedBeansInEachOther