KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opensubsystems > patterns > dialoglayout > www > DoubleSelectTag


1 /*
2  * Copyright (c) 2003 - 2007 OpenSubsystems s.r.o. Slovak Republic. All rights reserved.
3  *
4  * Project: OpenSubsystems
5  *
6  * $Id: DoubleSelectTag.java,v 1.17 2007/01/07 06:14:28 bastafidli Exp $
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; version 2 of the License.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  */

21  
22 package org.opensubsystems.patterns.dialoglayout.www;
23
24 import javax.servlet.http.HttpServletRequest JavaDoc;
25 import javax.servlet.jsp.JspException JavaDoc;
26
27 import org.opensubsystems.core.www.BlockElementTag;
28 import org.opensubsystems.core.www.TagUtils;
29
30 /**
31  * Custom tag to generate all HTML code necessary to display double select
32  * control, which contains 2 select lists and buttons that allow moving items
33  * between lists and optionally reordering items in the destination list.
34  *
35  * @version $Id: DoubleSelectTag.java,v 1.17 2007/01/07 06:14:28 bastafidli Exp $
36  * @author Julian Legeny
37  * @code.reviewer Miro Halas
38  * @code.reviewed 1.13 2006/02/18 05:29:32 bastafidli
39  */

40 public class DoubleSelectTag extends BlockElementTag
41 {
42    // Attributes ///////////////////////////////////////////////////////////////
43

44    /**
45     * Generated serial version id for this class.
46     */

47    private static final long serialVersionUID = -4101558432379629892L;
48
49    /**
50     * Value of the hidden parameter storing assigned items.
51     * Format of this variable are IDs separated by ','.
52     */

53    protected String JavaDoc m_strvalue;
54
55    /**
56     * Name of the hidden parameter used to identify submitted data
57     */

58    protected String JavaDoc m_strName;
59
60    // Constructors /////////////////////////////////////////////////////////////
61

62    /**
63     * Constructor for custom tag.
64     */

65    public DoubleSelectTag()
66    {
67       super("clsStrechControl", BlockElementTag.DIV_BLOCK_ELEMENT);
68       m_strIdSuffix = "dscmpsite";
69       m_strvalue = "";
70       m_strName = null;
71    }
72    
73    // Business logic ///////////////////////////////////////////////////////////
74

75    /**
76     * {@inheritDoc}
77     */

78    public int doStartTag() throws JspException JavaDoc
79    {
80       // Generate hidden parameter for storing assigned IDs
81
// within the destination (right) list
82
StringBuffer JavaDoc sbHtml = new StringBuffer JavaDoc();
83       StringBuffer JavaDoc sbID = new StringBuffer JavaDoc();
84
85       // getCurrentId() is fairly expensive so we call it just once and then we
86
// reuse the results.
87
String JavaDoc strCurrentId = getCurrentId();
88
89       // construct ID
90
sbID.append(strCurrentId);
91       sbID.append("_assigned_items");
92
93       // first try to get parameter from request
94
String JavaDoc strValue = ((HttpServletRequest JavaDoc)pageContext.getRequest()
95                             ).getParameter(sbID.toString());
96       
97       if (strValue == null)
98       {
99          // if value was not found in request, set up value externally
100
// defined within the tag attribute
101
strValue = m_strvalue;
102       }
103       
104       /*
105          <input type="hidden" id="XXX_assigned_items" name="XXX_assigned_items" value="">
106       */

107
108       sbHtml.append("<input type=\"hidden\" id=\"");
109       sbHtml.append(sbID);
110       sbHtml.append("\"");
111
112       if ((m_strName != null) || (m_strName.length() > 0))
113       {
114          sbHtml.append(" name=\"");
115          sbHtml.append(m_strName);
116          sbHtml.append("\"");
117       }
118       
119       sbHtml.append(" value=\"");
120       if ((strValue != null) || (strValue.length() > 0))
121       {
122          sbHtml.append(strValue);
123       }
124       sbHtml.append("\">\n");
125       
126       TagUtils.write(pageContext, sbHtml.toString());
127       
128       return super.doStartTag();
129    }
130
131    /**
132     * {@inheritDoc}
133     */

134    public int doEndTag() throws JspException JavaDoc
135    {
136       // And now generate the default end of the element
137
return super.doEndTag();
138    }
139
140    /**
141     * @return String - Name of the hidden parameter used to identify submitted data
142     */

143    public String JavaDoc getName()
144    {
145       return m_strName;
146    }
147
148    /**
149     * @return String - value used for getting hidden parameter storing
150     * assigned items within the destination list
151     */

152    public String JavaDoc getValue()
153    {
154       return m_strvalue;
155    }
156
157    /**
158     * @param strName - Name of the hidden parameter used to identify submitted data
159     */

160    public void setName(
161       String JavaDoc strName
162    )
163    {
164       m_strName = strName;
165    }
166
167    /**
168     * @param strValue - value used for setting up hidden parameter storing
169     * assigned items within the destination list
170     */

171    public void setValue(
172       String JavaDoc strValue
173    )
174    {
175       m_strvalue = strValue;
176    }
177 }
178
Popular Tags