HTML and CSS Reference
In-Depth Information
public void setTitle(String title) {
this.title = title;
}
public String getIndustry() {
return industry;
}
public void setIndustry(String industry) {
this.industry = industry;
}
}
Associating the
Profession
managed bean instance with the
User
managed bean instance can be done using
either the JSF configuration file or the JSF annotations. Listing 2-12 shows the part of the JSF configuration file which
configures the
Profession
managed bean to be injected in the
User
managed bean when it is instantiated.
Listing 2-12.
Configuring the Profession Instance to Be Injected in the User Instance
<managed-bean>
<managed-bean-name>user</managed-bean-name>
<managed-bean-class>com.jsfprohtml5.firstapplication.model.User</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
<
managed
-
property>
<property-name>profession</property-name>
<value>#{profession}</value>
</managed-property>
...
</managed-bean>
<managed-bean>
<managed-bean-name>profession</managed-bean-name>
<managed-bean-class>com.jsfprohtml5.firstapplication.model.Profession</managed-bean-class>
<managed-bean-scope>none</managed-bean-scope>
<managed-property>
<property-name>title</property-name>
<value>Software Engineer</value>
</managed-property>
<managed-property>
<property-name>industry</property-name>
<value>IT</value>
</managed-property>
</managed-bean>
The
Profession
managed bean is declared in the
none
scope in order to have the scope of its caller managed
bean which instantiates it (which is the
User
managed bean in this case). In the
User
managed bean, a property
initialization is defined for the
profession
property, and the
#{profession}
expression is used as the value for the
profession
property using the
<managed-property>
element.
After doing this configuration, the
Profession
managed bean will be instantiated and set in the session scope
when the
User
managed bean is instantiated by the JSF framework. This means that the
#{user.profession.title}
expression will return the initial value for the profession title, which is
"Software Engineer"
.