Skip to content

Commit

Permalink
Fix primefaces#11875: Remove deprecation and restore SubTable demo
Browse files Browse the repository at this point in the history
  • Loading branch information
melloware committed May 12, 2024
1 parent 7858293 commit 3e0a6e0
Show file tree
Hide file tree
Showing 7 changed files with 290 additions and 2 deletions.
5 changes: 5 additions & 0 deletions primefaces-showcase/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,11 @@
</webApp>
<scan>5</scan>
<webXml>${project.build.directory}/web.xml</webXml>
<httpConnector>
<host>0.0.0.0</host>
<port>8080</port>
<idleTimeout>60000</idleTimeout>
</httpConnector>
</configuration>
<dependencies>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* The MIT License
*
* Copyright (c) 2009-2024 PrimeTek Informatics
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.primefaces.showcase.domain;

import java.io.Serializable;

public class Stats implements Serializable {

private static final long serialVersionUID = 1L;

private String season;

private int win;

private int loss;

public Stats() {
// default constructor
}

public Stats(String season, int win, int loss) {
this.season = season;
this.win = win;
this.loss = loss;
}

public int getWin() {
return win;
}

public void setWin(int win) {
this.win = win;
}

public int getLoss() {
return loss;
}

public void setLoss(int loss) {
this.loss = loss;
}

public String getSeason() {
return season;
}

public void setSeason(String season) {
this.season = season;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* The MIT License
*
* Copyright (c) 2009-2024 PrimeTek Informatics
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.primefaces.showcase.domain;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class Team implements Serializable {

private static final long serialVersionUID = 1L;

private String name;

private List<Stats> stats;

public Team() {
stats = new ArrayList<Stats>();
}

public Team(String name) {
this.name = name;
stats = new ArrayList<Stats>();
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public List<Stats> getStats() {
return stats;
}

public void setStats(List<Stats> stats) {
this.stats = stats;
}

public int getAllWins() {
int sum = 0;

for (Stats s : stats) {
sum += s.getWin();
}

return sum;
}

public int getAllLosses() {
int sum = 0;

for (Stats s : stats) {
sum += s.getLoss();
}

return sum;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ public void init() {
dataTableMenuItems.add(new MenuItem("Sort", "/ui/data/datatable/sort"));
dataTableMenuItems.add(new MenuItem("StickyHeader", "/ui/data/datatable/sticky"));
dataTableMenuItems.add(new MenuItem("StripedRows", "/ui/data/datatable/striped"));
//dataTableMenuItems.add(new MenuItem("SubTable", "/ui/data/datatable/subTable"));
dataTableMenuItems.add(new MenuItem("SubTable", "/ui/data/datatable/subTable"));
//dataTableMenuItems.add(new MenuItem("SummaryRow", "/ui/data/datatable/summaryRow"));
dataMenuItems.add(new MenuItem("DataTable", dataTableMenuItems));

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* The MIT License
*
* Copyright (c) 2009-2024 PrimeTek Informatics
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.primefaces.showcase.view.data.datatable;

import java.util.ArrayList;
import java.util.List;

import org.primefaces.showcase.domain.Stats;
import org.primefaces.showcase.domain.Team;

import jakarta.annotation.PostConstruct;
import jakarta.enterprise.context.RequestScoped;
import jakarta.inject.Named;

@Named
@RequestScoped
public class SubTableView {

private List<Team> teams;

@PostConstruct
public void init() {
teams = new ArrayList<Team>();
Team lakers = new Team("Los Angeles Lakers");
lakers.getStats().add(new Stats("2005-2006", 50, 32));
lakers.getStats().add(new Stats("2006-2007", 44, 38));
lakers.getStats().add(new Stats("2007-2008", 40, 42));
lakers.getStats().add(new Stats("2008-2009", 45, 37));
lakers.getStats().add(new Stats("2009-2010", 48, 34));
lakers.getStats().add(new Stats("2010-2011", 42, 42));
teams.add(lakers);

Team celtics = new Team("Boston Celtics");
celtics.getStats().add(new Stats("2005-2006", 46, 36));
celtics.getStats().add(new Stats("2006-2007", 50, 32));
celtics.getStats().add(new Stats("2007-2008", 41, 41));
celtics.getStats().add(new Stats("2008-2009", 45, 37));
celtics.getStats().add(new Stats("2009-2010", 38, 44));
celtics.getStats().add(new Stats("2010-2011", 35, 47));
teams.add(celtics);
}

public List<Team> getTeams() {
return teams;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="jakarta.faces.facelets"
xmlns:h="jakarta.faces.html"
xmlns:p="http://primefaces.org/ui"
xmlns:f="jakarta.faces.core"
template="/WEB-INF/template.xhtml">

<ui:define name="title">
DataTable <span class="subitem">SubTable</span>
</ui:define>

<ui:define name="description">
SubTable is a helper component for grouping.
</ui:define>

<ui:param name="documentationLink" value="/components/datatable" />
<ui:param name="widgetLink" value="DataTable-1"/>

<ui:define name="implementation">
<h:form>
<div class="card">
<p:dataTable var="team" value="#{subTableView.teams}">
<f:facet name="header">
NBA Teams
</f:facet>

<p:columnGroup type="header">
<p:row>
<p:column rowspan="2" headerText="Team"/>
<p:column colspan="2" headerText="Stats"/>
</p:row>
<p:row>
<p:column headerText="Wins"/>
<p:column headerText="Losses"/>
</p:row>
</p:columnGroup>

<p:subTable var="stats" value="#{team.stats}">
<f:facet name="header">
<h:outputText value="#{team.name}"/>
</f:facet>
<p:column>
<h:outputText value="#{stats.season}"/>
</p:column>
<p:column>
<h:outputText value="#{stats.win}"/>
</p:column>
<p:column>
<h:outputText value="#{stats.loss}"/>
</p:column>
<p:columnGroup type="footer">
<p:row>
<p:column footerText="Totals: " class="text-right font-bold"/>
<p:column footerText="#{team.allWins}" class="font-bold"/>
<p:column footerText="#{team.allLosses}" class="font-bold"/>
</p:row>
</p:columnGroup>
</p:subTable>
</p:dataTable>
</div>
</h:form>
</ui:define>

</ui:composition>
Original file line number Diff line number Diff line change
Expand Up @@ -1571,7 +1571,6 @@ protected void encodeNativeRadio(FacesContext context, DataTable table, boolean
}

protected void encodeSubTable(FacesContext context, DataTable table, SubTable subTable, int first, int last) throws IOException {
logDevelopmentWarning(context, this, "SubTable is not recommended and may be removed in the future, use row grouping instead");
for (int i = first; i < last; i++) {
table.setRowIndex(i);
if (!table.isRowAvailable()) {
Expand Down

0 comments on commit 3e0a6e0

Please sign in to comment.