JSF Showcase
c:forEach
c:forEach have similar features and attributes than ui:repeat.General Usage
- INDEX: 0, China
- INDEX: 1, Switzerland
- INDEX: 2, United States
- INDEX: 3, United Kingdom
- INDEX: 4, Vietnam
Source Code
- <ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:c="http://xmlns.jcp.org/jsp/jstl/core"
- xmlns:h="http://xmlns.jcp.org/jsf/html" xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
- <ul>
- <c:forEach items="#{countryService.allCountries}" var="country" varStatus="metadata">
- <li style="background-color:#{ (metadata.odd ? 'grey' : 'white')}">
- <h:outputText value="#{i18n['index']}: #{metadata.index}, #{country.countryName}"/>
- </li>
- </c:forEach>
- </ul>
- </ui:composition>
- @ApplicationScoped
- @ManagedBean(name = "countryService")
- public class CountryServiceMockImpl implements CountryService, Serializable {
- // serialVersionUID
- private static final long serialVersionUID = 4289537697479875863L;
- // Private Data Members
- private List<Country> countryList;
- private Map<Long, Country> countryMap;
- @Override
- public List<Country> getAllCountries() {
- return countryList;
- }
- @Override
- public Country getCountryByCode(String countryCode) {
- Country country = null;
- for (Country curCountry : countryList) {
- if (curCountry.getCountryCode().equals(countryCode)) {
- country = curCountry;
- break;
- }
- }
- return country;
- }
- @Override
- public Map<Long, Country> getCountryMap() {
- return countryMap;
- }
- @PostConstruct
- public void postConstruct() {
- countryMap = new HashMap<Long, Country>();
- Country country = new Country(1, "CN", "China");
- countryMap.put(country.getCountryId(), country);
- country = new Country(2, "CH", "Switzerland");
- countryMap.put(country.getCountryId(), country);
- country = new Country(3, "US", "United States");
- countryMap.put(country.getCountryId(), country);
- country = new Country(4, "UK", "United Kingdom");
- countryMap.put(country.getCountryId(), country);
- country = new Country(5, "VN", "Vietnam");
- countryMap.put(country.getCountryId(), country);
- countryMap = Collections.unmodifiableMap(countryMap);
- countryList = Collections.unmodifiableList(new ArrayList<Country>(countryMap.values()));
- }
- }
- public class Country implements Serializable {
- // serialVersionUID
- private static final long serialVersionUID = 9135922470541735463L;
- // Private Data Members
- private long countryId;
- private String countryCode;
- private String countryName;
- public Country(long countryId, String countryCode, String countryName) {
- this.countryId = countryId;
- this.countryCode = countryCode;
- this.countryName = countryName;
- }
- public String getCountryCode() {
- return countryCode;
- }
- public long getCountryId() {
- return countryId;
- }
- public String getCountryName() {
- return countryName;
- }
- public void setCountryCode(String countryCode) {
- this.countryCode = countryCode;
- }
- public void setCountryId(long countryId) {
- this.countryId = countryId;
- }
- public void setCountryName(String countryName) {
- this.countryName = countryName;
- }
- }
Liferay Faces Bridge Implementation 5.0.0 + Showcase Common 3.1.1 + Liferay Faces Util 3.4.1 + Mojarra 2.2.20