Skip to content

Commit 45c778f

Browse files
admin: tax zones pager
1 parent d057ce0 commit 45c778f

File tree

9 files changed

+103
-104
lines changed

9 files changed

+103
-104
lines changed

src/main/java/org/woehlke/greenshop/admin/service/TaxZoneService.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package org.woehlke.greenshop.admin.service;
22

3+
import org.springframework.data.domain.Page;
4+
import org.springframework.data.domain.Pageable;
35
import org.woehlke.greenshop.admin.entities.TaxZone;
46

57
import java.util.List;
@@ -9,7 +11,7 @@
911
*/
1012
public interface TaxZoneService {
1113

12-
List<TaxZone> findAllTaxZones();
14+
Page<TaxZone> findAllTaxZones(Pageable pageRequest);
1315

1416
TaxZone findTaxZoneById(long taxZoneId);
1517

src/main/java/org/woehlke/greenshop/admin/service/TaxZoneServiceImpl.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package org.woehlke.greenshop.admin.service;
22

3+
import org.springframework.data.domain.Page;
4+
import org.springframework.data.domain.Pageable;
35
import org.springframework.transaction.annotation.Propagation;
46
import org.springframework.transaction.annotation.Transactional;
57
import org.woehlke.greenshop.admin.entities.TaxZone;
@@ -51,8 +53,8 @@ public void updateTaxZone(TaxZone thisTaxZone) {
5153
}
5254

5355
@Override
54-
public List<TaxZone> findAllTaxZones() {
55-
return taxZoneRepository.findAll();
56+
public Page<TaxZone> findAllTaxZones(Pageable pageRequest) {
57+
return taxZoneRepository.findAll(pageRequest);
5658
}
5759

5860
@Override

src/main/java/org/woehlke/greenshop/admin/web/taxes/TaxZoneController.java

Lines changed: 43 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22

33
import org.slf4j.Logger;
44
import org.slf4j.LoggerFactory;
5+
import org.springframework.data.domain.Page;
6+
import org.springframework.data.domain.PageRequest;
7+
import org.springframework.data.domain.Pageable;
8+
import org.springframework.data.domain.Sort;
59
import org.springframework.stereotype.Controller;
610
import org.springframework.ui.Model;
711
import org.springframework.validation.BindingResult;
8-
import org.springframework.web.bind.annotation.ModelAttribute;
9-
import org.springframework.web.bind.annotation.PathVariable;
10-
import org.springframework.web.bind.annotation.RequestMapping;
11-
import org.springframework.web.bind.annotation.RequestMethod;
12+
import org.springframework.web.bind.annotation.*;
1213
import org.woehlke.greenshop.admin.AdminMenuCategory;
1314
import org.woehlke.greenshop.admin.entities.TaxZone;
1415
import org.woehlke.greenshop.admin.entities.TaxZone2Zone;
@@ -46,15 +47,20 @@ public class TaxZoneController {
4647
@Inject
4748
private TaxZone2ZoneService taxZone2ZoneService;
4849

50+
private final static int PAGE_SIZE = 20;
51+
52+
private final static String FIRST_PAGE = "0";
53+
4954
@RequestMapping(value = "/admin/taxZones", method = RequestMethod.GET)
50-
public String taxZones(Model model){
55+
public String taxZones(@RequestParam(value="page",defaultValue=FIRST_PAGE) int page, Model model){
5156
int menuCategory = AdminMenuCategory.LOCATION_TAXES.ordinal();
5257
model.addAttribute("menuCategory",menuCategory);
53-
List<TaxZone> taxZones = taxZoneService.findAllTaxZones();
58+
Pageable pageRequest = new PageRequest(page,PAGE_SIZE, Sort.Direction.ASC, "name");
59+
Page<TaxZone> taxZones = taxZoneService.findAllTaxZones(pageRequest);
5460
model.addAttribute("taxZones",taxZones);
5561
TaxZone thisTaxZone = null;
5662
int numberOfZones = 0;
57-
if(taxZones.size()>0){
63+
if(taxZones.getContent().size()>0){
5864
thisTaxZone = taxZones.iterator().next();
5965
numberOfZones = taxZone2ZoneService.getNumberOfZonesForTaxZone(thisTaxZone);
6066
}
@@ -64,10 +70,12 @@ public String taxZones(Model model){
6470
}
6571

6672
@RequestMapping(value = "/admin/taxZones/{taxZoneId}", method = RequestMethod.GET)
67-
public String taxZoneId(@PathVariable long taxZoneId, Model model){
73+
public String taxZoneId(@RequestParam(value="page",defaultValue=FIRST_PAGE) int page,
74+
@PathVariable long taxZoneId, Model model){
6875
int menuCategory = AdminMenuCategory.LOCATION_TAXES.ordinal();
6976
model.addAttribute("menuCategory",menuCategory);
70-
List<TaxZone> taxZones = taxZoneService.findAllTaxZones();
77+
Pageable pageRequest = new PageRequest(page,PAGE_SIZE, Sort.Direction.ASC, "name");
78+
Page<TaxZone> taxZones = taxZoneService.findAllTaxZones(pageRequest);
7179
model.addAttribute("taxZones",taxZones);
7280
TaxZone thisTaxZone = taxZoneService.findTaxZoneById(taxZoneId);
7381
int numberOfZones = taxZone2ZoneService.getNumberOfZonesForTaxZone(thisTaxZone);
@@ -77,21 +85,24 @@ public String taxZoneId(@PathVariable long taxZoneId, Model model){
7785
}
7886

7987
@RequestMapping(value = "/admin/taxZones/insert", method = RequestMethod.GET)
80-
public String taxZonesInsertForm(Model model){
88+
public String taxZonesInsertForm(@RequestParam(value="page",defaultValue=FIRST_PAGE) int page,Model model){
8189
int menuCategory = AdminMenuCategory.LOCATION_TAXES.ordinal();
8290
model.addAttribute("menuCategory",menuCategory);
83-
List<TaxZone> taxZones = taxZoneService.findAllTaxZones();
91+
Pageable pageRequest = new PageRequest(page,PAGE_SIZE, Sort.Direction.ASC, "name");
92+
Page<TaxZone> taxZones = taxZoneService.findAllTaxZones(pageRequest);
8493
model.addAttribute("taxZones",taxZones);
8594
TaxZone thisTaxZone = new TaxZone();
8695
model.addAttribute("thisTaxZone",thisTaxZone);
8796
return "admin/taxZonesInsertForm";
8897
}
8998

9099
@RequestMapping(value = "/admin/taxZones/insert", method = RequestMethod.POST)
91-
public String taxZonesInsertSave(@Valid TaxZone thisTaxZone, BindingResult result, Model model){
100+
public String taxZonesInsertSave(@RequestParam(value="page",defaultValue=FIRST_PAGE) int page,
101+
@Valid TaxZone thisTaxZone, BindingResult result, Model model){
92102
int menuCategory = AdminMenuCategory.LOCATION_TAXES.ordinal();
93103
model.addAttribute("menuCategory",menuCategory);
94-
List<TaxZone> taxZones = taxZoneService.findAllTaxZones();
104+
Pageable pageRequest = new PageRequest(page,PAGE_SIZE, Sort.Direction.ASC, "name");
105+
Page<TaxZone> taxZones = taxZoneService.findAllTaxZones(pageRequest);
95106
model.addAttribute("taxZones",taxZones);
96107
if(result.hasErrors()){
97108
logger.info(result.toString());
@@ -102,15 +113,17 @@ public String taxZonesInsertSave(@Valid TaxZone thisTaxZone, BindingResult resul
102113
thisTaxZone.setDateAdded(new Date());
103114
thisTaxZone = taxZoneService.createTaxZone(thisTaxZone);
104115
model.addAttribute("thisTaxZone",thisTaxZone);
105-
return "redirect:/admin/taxZones/"+thisTaxZone.getId();
116+
return "redirect:/admin/taxZones/"+thisTaxZone.getId()+"?page="+page;
106117
}
107118
}
108119

109120
@RequestMapping(value = "/admin/taxZones/delete/{taxZoneId}", method = RequestMethod.GET)
110-
public String taxZoneDeleteForm(@PathVariable long taxZoneId, Model model){
121+
public String taxZoneDeleteForm(@RequestParam(value="page",defaultValue=FIRST_PAGE) int page,
122+
@PathVariable long taxZoneId, Model model){
111123
int menuCategory = AdminMenuCategory.LOCATION_TAXES.ordinal();
112124
model.addAttribute("menuCategory",menuCategory);
113-
List<TaxZone> taxZones = taxZoneService.findAllTaxZones();
125+
Pageable pageRequest = new PageRequest(page,PAGE_SIZE, Sort.Direction.ASC, "name");
126+
Page<TaxZone> taxZones = taxZoneService.findAllTaxZones(pageRequest);
114127
model.addAttribute("taxZones",taxZones);
115128
TaxZone thisTaxZone = taxZoneService.findTaxZoneById(taxZoneId);
116129
int numberOfZones = taxZone2ZoneService.getNumberOfZonesForTaxZone(thisTaxZone);
@@ -120,26 +133,30 @@ public String taxZoneDeleteForm(@PathVariable long taxZoneId, Model model){
120133
}
121134

122135
@RequestMapping(value = "/admin/taxZones/delete/{taxZoneId}", method = RequestMethod.POST)
123-
public String taxZoneDeletePerform(@PathVariable long taxZoneId,
136+
public String taxZoneDeletePerform(@RequestParam(value="page",defaultValue=FIRST_PAGE) int page,
137+
@PathVariable long taxZoneId,
124138
@Valid TaxZone thisTaxZone,
125139
BindingResult result,
126140
Model model){
127141
int menuCategory = AdminMenuCategory.LOCATION_TAXES.ordinal();
128142
model.addAttribute("menuCategory",menuCategory);
129-
List<TaxZone> taxZones = taxZoneService.findAllTaxZones();
143+
Pageable pageRequest = new PageRequest(page,PAGE_SIZE, Sort.Direction.ASC, "name");
144+
Page<TaxZone> taxZones = taxZoneService.findAllTaxZones(pageRequest);
130145
model.addAttribute("taxZones",taxZones);
131146
thisTaxZone = taxZoneService.findTaxZoneById(taxZoneId);
132147
if(thisTaxZone != null) {
133148
taxZoneService.deleteTaxZones(thisTaxZone);
134149
}
135-
return "redirect:/admin/taxZones";
150+
return "redirect:/admin/taxZones?page="+page;
136151
}
137152

138153
@RequestMapping(value = "/admin/taxZones/edit/{taxZoneId}", method = RequestMethod.GET)
139-
public String taxZoneEditForm(@PathVariable long taxZoneId, Model model){
154+
public String taxZoneEditForm(@RequestParam(value="page",defaultValue=FIRST_PAGE) int page,
155+
@PathVariable long taxZoneId, Model model){
140156
int menuCategory = AdminMenuCategory.LOCATION_TAXES.ordinal();
141157
model.addAttribute("menuCategory",menuCategory);
142-
List<TaxZone> taxZones = taxZoneService.findAllTaxZones();
158+
Pageable pageRequest = new PageRequest(page,PAGE_SIZE, Sort.Direction.ASC, "name");
159+
Page<TaxZone> taxZones = taxZoneService.findAllTaxZones(pageRequest);
143160
model.addAttribute("taxZones",taxZones);
144161
TaxZone thisTaxZone = taxZoneService.findTaxZoneById(taxZoneId);
145162
int numberOfZones = taxZone2ZoneService.getNumberOfZonesForTaxZone(thisTaxZone);
@@ -149,20 +166,22 @@ public String taxZoneEditForm(@PathVariable long taxZoneId, Model model){
149166
}
150167

151168
@RequestMapping(value = "/admin/taxZones/edit/{taxZoneId}", method = RequestMethod.POST)
152-
public String taxZoneEditPerform(@PathVariable long taxZoneId,
169+
public String taxZoneEditPerform(@RequestParam(value="page",defaultValue=FIRST_PAGE) int page,
170+
@PathVariable long taxZoneId,
153171
@Valid TaxZone thisTaxZone,
154172
BindingResult result,
155173
Model model){
156174
int menuCategory = AdminMenuCategory.LOCATION_TAXES.ordinal();
157175
model.addAttribute("menuCategory",menuCategory);
158-
List<TaxZone> taxZones = taxZoneService.findAllTaxZones();
176+
Pageable pageRequest = new PageRequest(page,PAGE_SIZE, Sort.Direction.ASC, "name");
177+
Page<TaxZone> taxZones = taxZoneService.findAllTaxZones(pageRequest);
159178
model.addAttribute("taxZones",taxZones);
160179
if(result.hasErrors()) {
161180
model.addAttribute("thisTaxZone",thisTaxZone);
162181
return "admin/taxZonesEditForm";
163182
} else {
164183
taxZoneService.updateTaxZone(thisTaxZone);
165-
return "redirect:/admin/taxZones/"+taxZoneId;
184+
return "redirect:/admin/taxZones/"+taxZoneId+"?page="+page;
166185
}
167186
}
168187

src/main/webapp/WEB-INF/jsp/admin/taxZones.jsp

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,30 +18,14 @@
1818
<td class="dataTableHeadingContent">Tax Zones</td>
1919
<td class="dataTableHeadingContent" align="right">Action&nbsp;</td>
2020
</tr>
21-
<c:forEach var="taxZone" items="${taxZones}">
22-
<c:if test="${taxZone.id == thisTaxZone.id}">
23-
<tr id="defaultSelected" class="dataTableRowSelected" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="document.location.href='http://localhost/oscommerce2/admin/geo_zones.php?zpage=1&zID=2&action=list'">
24-
<td class="dataTableContent"><a href="<c:url value="/admin/taxZone/${taxZone.id}"/>"><img src="resources/admin/images/icons/folder.gif" border="0" alt="Folder" title="Folder" /></a>&nbsp;${taxZone.name}</td>
25-
<td class="dataTableContent" align="right"><img src="resources/admin/images/icon_arrow_right.gif" border="0" alt="" />&nbsp;</td>
26-
</tr>
27-
</c:if>
28-
<c:if test="${taxZone.id != thisTaxZone.id}">
29-
<tr class="dataTableRow" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="document.location.href='<c:url value="/admin/taxZones/${taxZone.id}"/>'">
30-
<td class="dataTableContent"><a href="<c:url value="/admin/taxZone/${taxZone.id}"/>"><img src="resources/admin/images/icons/folder.gif" border="0" alt="Folder" title="Folder" /></a>&nbsp;${taxZone.name}</td>
31-
<td class="dataTableContent" align="right"><a href="<c:url value="/admin/taxZones/${taxZone.id}"/>"><img src="resources/admin/images/icon_info.gif" border="0" alt="Info" title="Info" /></a>&nbsp;</td>
32-
</tr>
33-
</c:if>
34-
</c:forEach>
21+
<c:import url="taxZonesDataTable.jsp" />
3522
<tr>
3623
<td colspan="2"><table border="0" width="100%" cellspacing="0" cellpadding="2">
37-
<tr>
38-
<td class="smallText">Displaying <strong>1</strong> to <strong>2</strong> (of <strong>2</strong> tax zones)</td>
39-
<td class="smallText" align="right">Page 1 of 1</td>
40-
</tr>
24+
<c:import url="taxZonesPager.jsp" />
4125
</table></td>
4226
</tr>
4327
<tr>
44-
<td class="smallText" align="right" colspan="2"><span class="tdbLink"><a id="tdb1" href="<c:url value="/admin/taxZones/insert"/>">Insert</a></span><script type="text/javascript">$("#tdb1").button({icons:{primary:"ui-icon-plus"}}).addClass("ui-priority-secondary").parent().removeClass("tdbLink");</script></td>
28+
<td class="smallText" align="right" colspan="2"><span class="tdbLink"><a id="tdb1" href="<c:url value="/admin/taxZones/insert?page=${taxZones.number}"/>">Insert</a></span><script type="text/javascript">$("#tdb1").button({icons:{primary:"ui-icon-plus"}}).addClass("ui-priority-secondary").parent().removeClass("tdbLink");</script></td>
4529
</tr>
4630
</table>
4731
</td>
@@ -53,7 +37,7 @@
5337
</table>
5438
<table border="0" width="100%" cellspacing="0" cellpadding="2">
5539
<tr>
56-
<td align="center" class="infoBoxContent"><span class="tdbLink"><a id="tdb2" href="<c:url value="/admin/taxZones/edit/${thisTaxZone.id}"/>">Edit</a></span><script type="text/javascript">$("#tdb2").button({icons:{primary:"ui-icon-document"}}).addClass("ui-priority-secondary").parent().removeClass("tdbLink");</script><span class="tdbLink"><a id="tdb3" href="<c:url value="/admin/taxZones/delete/${thisTaxZone.id}"/>">Delete</a></span><script type="text/javascript">$("#tdb3").button({icons:{primary:"ui-icon-trash"}}).addClass("ui-priority-secondary").parent().removeClass("tdbLink");</script><span class="tdbLink"><a id="tdb4" href="<c:url value="/admin/taxZone/${thisTaxZone.id}"/>">Details</a></span><script type="text/javascript">$("#tdb4").button({icons:{primary:"ui-icon-info"}}).addClass("ui-priority-secondary").parent().removeClass("tdbLink");</script></td>
40+
<td align="center" class="infoBoxContent"><span class="tdbLink"><a id="tdb2" href="<c:url value="/admin/taxZones/edit/${thisTaxZone.id}?page=${taxZones.number}"/>">Edit</a></span><script type="text/javascript">$("#tdb2").button({icons:{primary:"ui-icon-document"}}).addClass("ui-priority-secondary").parent().removeClass("tdbLink");</script><span class="tdbLink"><a id="tdb3" href="<c:url value="/admin/taxZones/delete/${thisTaxZone.id}?page=${taxZones.number}"/>">Delete</a></span><script type="text/javascript">$("#tdb3").button({icons:{primary:"ui-icon-trash"}}).addClass("ui-priority-secondary").parent().removeClass("tdbLink");</script><span class="tdbLink"><a id="tdb4" href="<c:url value="/admin/taxZone/${thisTaxZone.id}"/>">Details</a></span><script type="text/javascript">$("#tdb4").button({icons:{primary:"ui-icon-info"}}).addClass("ui-priority-secondary").parent().removeClass("tdbLink");</script></td>
5741
</tr>
5842
<tr>
5943
<td class="infoBoxContent"><br />Number of Zones: ${numberOfZones}</td>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<%@ include file="/WEB-INF/layout/taglibs.jsp"%>
2+
<c:forEach var="taxZone" items="${taxZones.content}">
3+
<c:if test="${taxZone.id == thisTaxZone.id}">
4+
<tr id="defaultSelected" class="dataTableRowSelected" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="document.location.href='<c:url value="/admin/taxZone/${taxZone.id}"/>'">
5+
<td class="dataTableContent"><a href="<c:url value="/admin/taxZone/${taxZone.id}"/>"><img src="resources/admin/images/icons/folder.gif" border="0" alt="Folder" title="Folder" /></a>&nbsp;${taxZone.name}</td>
6+
<td class="dataTableContent" align="right"><img src="resources/admin/images/icon_arrow_right.gif" border="0" alt="" />&nbsp;</td>
7+
</tr>
8+
</c:if>
9+
<c:if test="${taxZone.id != thisTaxZone.id}">
10+
<tr class="dataTableRow" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="document.location.href='<c:url value="/admin/taxZones/${taxZone.id}?page=${taxZones.number}"/>'">
11+
<td class="dataTableContent"><a href="<c:url value="/admin/taxZone/${taxZone.id}"/>"><img src="resources/admin/images/icons/folder.gif" border="0" alt="Folder" title="Folder" /></a>&nbsp;${taxZone.name}</td>
12+
<td class="dataTableContent" align="right"><a href="<c:url value="/admin/taxZones/${taxZone.id}?page=${taxZones.number}"/>"><img src="resources/admin/images/icon_info.gif" border="0" alt="Info" title="Info" /></a>&nbsp;</td>
13+
</tr>
14+
</c:if>
15+
</c:forEach>

0 commit comments

Comments
 (0)