KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > dbforms > taglib > DbSortTag


1 /*
2  * $Header: /cvsroot/jdbforms/dbforms/src/org/dbforms/taglib/DbSortTag.java,v 1.18 2004/08/18 12:26:08 hkollmann Exp $
3  * $Revision: 1.18 $
4  * $Date: 2004/08/18 12:26:08 $
5  *
6  * DbForms - a Rapid Application Development Framework
7  * Copyright (C) 2001 Joachim Peer <joepeer@excite.com>
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22  */

23
24 package org.dbforms.taglib;
25
26 import org.apache.commons.logging.Log;
27 import org.apache.commons.logging.LogFactory;
28
29 import org.dbforms.util.*;
30
31 import java.util.*;
32
33 import javax.servlet.http.*;
34 import javax.servlet.jsp.*;
35
36
37
38 /**
39  * this tag renders a dabase-datadriven LABEL, which is apassive element (it
40  * can't be changed by the user) - it is predestinated for use with read-only
41  * data (i.e. primary keys you don't want the user to change, etc)
42  *
43  * @author Joachim Peer
44  */

45 public class DbSortTag extends DbBaseHandlerTag
46    implements javax.servlet.jsp.tagext.TryCatchFinally JavaDoc {
47    private static Log logCat = LogFactory.getLog(DbSortTag.class); // logging category for this class
48

49    /**
50     * @see javax.servlet.jsp.tagext.TryCatchFinally#doCatch(java.lang.Throwable)
51     */

52    public void doCatch(Throwable JavaDoc t) throws Throwable JavaDoc {
53       throw t;
54    }
55
56
57    /**
58     * DOCUMENT ME!
59     *
60     * @return DOCUMENT ME!
61     *
62     * @throws javax.servlet.jsp.JspException DOCUMENT ME!
63     * @throws JspException DOCUMENT ME!
64     */

65    public int doEndTag() throws javax.servlet.jsp.JspException JavaDoc {
66       try {
67          if (!getField()
68                        .hasIsKeySet() && !getField()
69                                                    .hasSortableSet()) {
70             logCat.warn("you should declare " + getField().getName()
71                         + " as key or as sortable in your config file, if you use it as ordering field!");
72          }
73
74          HttpServletRequest request = (HttpServletRequest) pageContext
75                                       .getRequest();
76
77          String JavaDoc oldValue = ParseUtil.getParameter(request,
78                                                               getField().getSortFieldName());
79
80          StringBuffer JavaDoc tagBuf = new StringBuffer JavaDoc();
81          tagBuf.append("<select name=\"");
82          tagBuf.append(getField().getSortFieldName());
83          tagBuf.append("\" size=\"0\" onChange=\"javascript:document.dbform.submit()\" >");
84
85          String JavaDoc strAsc = "Ascending";
86          String JavaDoc strDesc = "Descending";
87          String JavaDoc strNone = "None";
88
89          // Internationalization
90
if (getParentForm()
91                       .hasCaptionResourceSet()) {
92             Locale reqLocale = MessageResources.getLocale(request);
93
94             // get message resource or if null take the default (english)
95
strAsc = MessageResources.getMessage("dbforms.select.sort.ascending",
96                                                  reqLocale, "Ascending");
97             strDesc = MessageResources.getMessage("dbforms.select.sort.descending",
98                                                   reqLocale, "Descending");
99             strNone = MessageResources.getMessage("dbforms.select.sort.none",
100                                                   reqLocale, "None");
101          }
102
103          // ---- ascending ----
104
tagBuf.append("<option value=\"asc\"");
105
106          if ("asc".equalsIgnoreCase(oldValue)) {
107             tagBuf.append(" selected ");
108          }
109
110          tagBuf.append(">")
111                .append(strAsc);
112
113          // ---- descending ----
114
tagBuf.append("<option value=\"desc\"");
115
116          if ("desc".equalsIgnoreCase(oldValue)) {
117             tagBuf.append(" selected ");
118          }
119
120          tagBuf.append(">")
121                .append(strDesc);
122
123          // ---- no sorting ----
124
tagBuf.append("<option value=\"none\" ");
125
126          if ((oldValue == null) || "none".equals(oldValue)) {
127             tagBuf.append(" selected ");
128          }
129
130          tagBuf.append(">")
131                .append(strNone);
132
133          tagBuf.append("</select>");
134
135          pageContext.getOut()
136                     .write(tagBuf.toString());
137       } catch (java.io.IOException JavaDoc ioe) {
138          throw new JspException("IO Error: " + ioe.getMessage());
139       }
140
141       return EVAL_PAGE;
142    }
143
144
145    /**
146     * DOCUMENT ME!
147     */

148    public void doFinally() {
149       super.doFinally();
150    }
151 }
152
Popular Tags