KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > fr > improve > struts > taglib > layout > pager > StatusTag


1 package fr.improve.struts.taglib.layout.pager;
2
3 import javax.servlet.jsp.JspException JavaDoc;
4
5 import fr.improve.struts.taglib.layout.LayoutTagSupport;
6 import fr.improve.struts.taglib.layout.event.EndLayoutEvent;
7 import fr.improve.struts.taglib.layout.event.StartLayoutEvent;
8 import fr.improve.struts.taglib.layout.util.LayoutUtils;
9 import fr.improve.struts.taglib.layout.util.TagUtils;
10
11 /**
12  * @author jnribette
13  */

14 public class StatusTag extends LayoutTagSupport {
15     protected int numberOfPage;
16     protected int currentPageNumber;
17     protected int size;
18     protected int itemsPerPage;
19     protected String JavaDoc styleClass;
20     protected String JavaDoc key;
21     protected String JavaDoc width;
22         
23     public int doStartLayoutTag() throws JspException JavaDoc {
24         boolean lc_isNested = Boolean.TRUE.equals(new StartLayoutEvent(this, null).send());
25         Integer JavaDoc[] lc_infos = (Integer JavaDoc[]) new PagerStatusEvent(this, null).send();
26         currentPageNumber = lc_infos[0].intValue();
27         numberOfPage = lc_infos[1].intValue();
28         size = lc_infos[2].intValue();
29         itemsPerPage = lc_infos[3].intValue();
30         
31         if (numberOfPage > 1) {
32             StringBuffer JavaDoc lc_buffer = new StringBuffer JavaDoc("");
33             if (!lc_isNested) {
34                 lc_buffer.append("<table border=\"0\" cellspacing=\"1\" cellpadding=\"1\"");
35                 if (width!=null) {
36                     lc_buffer.append(" width=\"");
37                     lc_buffer.append(width);
38                     lc_buffer.append("\"");
39                 }
40                 lc_buffer.append(" class=\"PAGER\"><tr>");
41             }
42             lc_buffer.append("<td");
43             if (styleClass!=null) {
44                 lc_buffer.append(" class=\"");
45                 lc_buffer.append(styleClass);
46                 lc_buffer.append("\"");
47             }
48             lc_buffer.append(">");
49             if (key!=null) {
50                 String JavaDoc[] lc_args = new String JavaDoc[5];
51                 lc_args[0] = String.valueOf(currentPageNumber + 1);
52                 lc_args[1] = String.valueOf(numberOfPage);
53                 lc_args[2] = String.valueOf(size);
54                 lc_args[3] = String.valueOf(currentPageNumber * itemsPerPage +1);
55                 int lc_lastItemDisplay = (currentPageNumber+1) * itemsPerPage;
56                 if (lc_lastItemDisplay > size) {
57                     lc_lastItemDisplay = size;
58                 }
59                 lc_args[4] = String.valueOf(lc_lastItemDisplay);
60                 lc_buffer.append(LayoutUtils.getLabel(pageContext, key, lc_args));
61             } else {
62                 lc_buffer.append(currentPageNumber+1);
63                 lc_buffer.append("/");
64                 lc_buffer.append(numberOfPage);
65             }
66             lc_buffer.append("</td>");
67             if (!lc_isNested) {
68                 lc_buffer.append("</tr></table>");
69             }
70             TagUtils.write(pageContext, lc_buffer.toString());
71         }
72         
73         return EVAL_BODY_INCLUDE;
74     }
75     public int doEndLayoutTag() throws JspException JavaDoc {
76         new EndLayoutEvent(this, null).send();
77         
78         numberOfPage = 0;
79         currentPageNumber = 0;
80         size = 0;
81         itemsPerPage = 0;
82                 
83         return EVAL_PAGE;
84     }
85     public void release() {
86         super.release();
87         styleClass = null;
88         key = null;
89     }
90     
91     /**
92      * Sets the styleClass.
93      * @param styleClass The styleClass to set
94      */

95     public void setStyleClass(String JavaDoc styleClass) {
96         this.styleClass = styleClass;
97     }
98
99     /**
100      * Sets the key.
101      * @param key The key to set
102      */

103     public void setKey(String JavaDoc key) {
104         this.key = key;
105     }
106
107     /**
108      * Sets the width.
109      * @param width The width to set
110      */

111     public void setWidth(String JavaDoc width) {
112         this.width = width;
113     }
114
115 }
116
Popular Tags