HTML and CSS Reference
In-Depth Information
Listing 2-6. The User Managed Bean with the Two New Properties
import java.util.List;
import java.util.Map;
//...
public class User implements Serializable {
private String name;
private String password;
private List<String> favoriteSports;
private Map<String, String> spokenLanguages;
// setters and getters ...
}
In order to initialize the favoriteSports List with some initial values, you can use the <list-entries> element
in the <managed-property> element, as shown by Listing 2-7.
Listing 2-7. Initialization of the List Property in the Faces Configuration File
<managed-property>
<property-name>favoriteSports</property-name>
<list-entries>
<value>Handball</value>
<value>Football</value>
<value>Basketball</value>
</list-entries>
</managed-property>
In the XHTML page, you can iterate on the favoriteSport list as shown in Listing 2-8 using the <ui:repeat> .
Listing 2-8. Displaying the favoriteSports Items in the XHTML Page
<b>You have the following initial list of favorite sports:</b>
<ul>
<ui:repeat value="#{user.favoriteSport}" var="sport">
<li>#{sport}</li>
</ui:repeat>
</ul>
If you want to display a specific item in the favoriteSport list, you can use the [] operator. For example, the
following #{user.favoriteSport[0]} will display the first item in the favoriteSport array, which is "Handball" . In
order to initialize the spokenLanguages Map with some initial values, you can use the <map-entries> element in the
<managed-property> element, as shown by Listing 2-9.
Listing 2-9. Initialization of the Map Property in the Faces Configuration File
<managed-property>
<property-name>spokenLanguages</property-name>
<map-entries>
<map-entry>
<key>EN</key>
 
Search WWH ::




Custom Search