<pe:masterDetail id="masterDetail" level="#{simpleMasterDetailController.currentLevel}">
<pe:masterDetailLevel level="1" levelLabel="Sports">
<p:dataTable id="sports" value="#{simpleMasterDetailController.sports}" var="sport">
<p:column headerText="Sport">
<p:commandLink value="#{sport.name}">
<pe:selectDetailLevel contextValue="#{sport}"/>
</p:commandLink>
</p:column>
<p:column headerText="Number of countries with leagues">
<h:outputText value="#{fn:length(sport.countriesWithLeague)}"/>
</p:column>
</p:dataTable>
</pe:masterDetailLevel>
<pe:masterDetailLevel level="2" contextVar="sport" levelLabel="Countries having #{sport.name} leagues">
<p:dataTable id="countries" value="#{sport.countriesWithLeague}" var="country">
<p:column headerText="Country">
<p:commandLink value="#{country.name}">
<pe:selectDetailLevel contextValue="#{country}"/>
</p:commandLink>
</p:column>
<p:column headerText="Code">
<h:outputText value="#{country.code}"/>
</p:column>
</p:dataTable>
</pe:masterDetailLevel>
<pe:masterDetailLevel level="3" contextVar="country" levelLabel="#{country.sport} leagues of #{country.name}">
<p:dataTable id="leauges" value="#{country.leagues}" var="league">
<p:column headerText="League">
<h:outputText value="#{league.name}"/>
</p:column>
<p:column headerText="Number of teams">
<h:outputText value="#{league.numberOfTeam}"/>
</p:column>
</p:dataTable>
<h:panelGrid columns="2" style="margin-top: 10px">
<p:commandButton value="Go to Sports" icon="pi pi-fast-backward">
<pe:selectDetailLevel level="1"/>
</p:commandButton>
<p:commandButton value="Go to Countries" icon="pi pi-step-backward">
<pe:selectDetailLevel step="-1"/>
</p:commandButton>
</h:panelGrid>
</pe:masterDetailLevel>
</pe:masterDetail>
@Named
@ViewScoped
public class SimpleMasterDetailController implements Serializable {
private static final long serialVersionUID = 20111120L;
private List<Sport> sports;
private int currentLevel = 1;
public SimpleMasterDetailController() {
if (sports == null) {
sports = new ArrayList<Sport>();
// football
List<Country> countries = new ArrayList<Country>();
Country country = new Country("Switzerland", "CH", "Football", getLeagues("Switzerland"));
countries.add(country);
country = new Country("England", "UK", "Football", getLeagues("England"));
countries.add(country);
country = new Country("Spain", "ES", "Football", getLeagues("Spain"));
countries.add(country);
country = new Country("Netherlands", "NL", "Football", getLeagues("Netherlands"));
countries.add(country);
sports.add(new Sport("Football", countries));
// basketball
countries = new ArrayList<Country>();
country = new Country("Germany", "DE", "Basketball", getLeagues("Germany"));
countries.add(country);
country = new Country("USA", "US", "Basketball", getLeagues("USA"));
countries.add(country);
country = new Country("Poland", "PL", "Basketball", getLeagues("Poland"));
countries.add(country);
sports.add(new Sport("Basketball", countries));
// ice hockey
countries = new ArrayList<Country>();
country = new Country("Russia", "RU", "Ice Hockey", getLeagues("Russia"));
countries.add(country);
country = new Country("Canada", "CA", "Ice Hockey", getLeagues("Canada"));
countries.add(country);
sports.add(new Sport("Ice Hockey", countries));
}
}
public List<Sport> getSports() {
return sports;
}
public int getCurrentLevel() {
return currentLevel;
}
public void setCurrentLevel(final int currentLevel) {
this.currentLevel = currentLevel;
}
private List<League> getLeagues(final String country) {
final List<League> leagues = new ArrayList<League>();
leagues.add(new League(country + " SuperLeague", 20));
leagues.add(new League(country + " NotBadLeague", 15));
leagues.add(new League(country + " CrapLeague", 30));
return leagues;
}
}
public class Sport implements Serializable {
private static final long serialVersionUID = 20111120L;
private String name;
private List<Country> countriesWithLeague;
public Sport(String name, List<Country> countriesWithLeague) {
this.name = name;
this.countriesWithLeague = countriesWithLeague;
}
public String getName() {
return name;
}
public List<Country> getCountriesWithLeague() {
return countriesWithLeague;
}
}
public class Country implements Serializable {
private static final long serialVersionUID = 20111120L;
private String name;
private String code;
private String sport;
private List<League> leagues;
public Country(String name, String code, String sport, List<League> leagues) {
this.name = name;
this.code = code;
this.sport = sport;
this.leagues = leagues;
}
public String getName() {
return name;
}
public String getCode() {
return code;
}
public String getSport() {
return sport;
}
public List<League> getLeagues() {
return leagues;
}
}
public class League implements Serializable {
private static final long serialVersionUID = 20111120L;
private String name;
private int numberOfTeam;
public League(String name, int numberOfTeam) {
this.name = name;
this.numberOfTeam = numberOfTeam;
}
public String getName() {
return name;
}
public int getNumberOfTeam() {
return numberOfTeam;
}
}