KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > mlw > vlh > web > tag > DefaultColumnCheckBoxTag


1 /**
2  * Copyright (c) 2003 held jointly by the individual authors.
3  *
4  * This library is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU Lesser General Public License as published
6  * by the Free Software Foundation; either version 2.1 of the License, or
7  * (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; with out even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with this library; if not, write to the Free Software Foundation,
16  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17  *
18  * > http://www.gnu.org/copyleft/lesser.html
19  * > http://www.opensource.org/licenses/lgpl-license.php
20  */

21 package net.mlw.vlh.web.tag;
22
23 import java.util.Locale JavaDoc;
24
25 import javax.servlet.http.HttpServletRequest JavaDoc;
26 import javax.servlet.jsp.JspException JavaDoc;
27 import javax.servlet.jsp.tagext.BodyContent JavaDoc;
28
29 import net.mlw.vlh.web.ValueListConfigBean;
30 import net.mlw.vlh.web.tag.support.ColumnInfo;
31 import net.mlw.vlh.web.util.JspUtils;
32
33 import org.apache.commons.beanutils.PropertyUtils;
34
35 /**
36  *
37  * @ author Matthew L. Wilson, Andrej Zachar
38  * @version $Revision: 1.10 $ $Date: 2006/01/06 10:53:54 $
39  */

40 public class DefaultColumnCheckBoxTag extends BaseColumnTag
41 {
42
43    private String JavaDoc name;
44
45    private String JavaDoc property;
46
47    /**
48     * @see javax.servlet.jsp.tagext.Tag#doEndTag()
49     */

50    public int doEndTag() throws JspException JavaDoc
51    {
52
53       ValueListSpaceTag rootTag = (ValueListSpaceTag) JspUtils.getParent(this, ValueListSpaceTag.class);
54       ValueListConfigBean config = rootTag.getConfig();
55
56       DefaultRowTag rowTag = (DefaultRowTag) JspUtils.getParent(this, DefaultRowTag.class);
57       appendClassCellAttribute(rowTag.getRowStyleClass());
58
59       Locale JavaDoc locale = config.getLocaleResolver().resolveLocale((HttpServletRequest JavaDoc) pageContext.getRequest());
60
61       if (rowTag.getCurrentRowNumber() == 0)
62       {
63          String JavaDoc titleKey = getTitleKey();
64          String JavaDoc label = (titleKey == null) ? getTitle() : config.getMessageSource().getMessage(titleKey, null, titleKey, locale);
65
66          StringBuffer JavaDoc header = new StringBuffer JavaDoc(512);
67          if (label != null)
68          {
69             header.append(label);
70          }
71
72          header
73                .append("<input type=\"checkbox\" onclick=\"for(i=0; i < this.form.elements.length; i++) {if (this.form.elements[i].name=='")
74                .append(getName()).append("') {this.form.elements[i].checked = this.checked;}}\"/>");
75
76          ColumnInfo columnInfo = new ColumnInfo(config.getDisplayHelper().help(pageContext, header.toString()), property, null,
77                getAttributes());
78
79          // Process toolTip if any
80
// toolTip or toolTipKey is set => get the string and put it into the ColumnInfo
81
String JavaDoc toolTipKey = getToolTipKey();
82          columnInfo.setToolTip((toolTipKey == null) ? getToolTip() : config.getMessageSource().getMessage(toolTipKey, null, toolTipKey,
83                locale));
84
85          rowTag.addColumnInfo(columnInfo);
86       }
87
88       Object JavaDoc bean = pageContext.getAttribute(rowTag.getBeanName());
89       Object JavaDoc value = "na";
90
91       try
92       {
93          value = PropertyUtils.getProperty(bean, property);
94       }
95       catch (Exception JavaDoc e)
96       {
97       }
98
99       StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
100
101       sb.append(rowTag.getDisplayProvider().getCellPreProcess(getCellAttributes()));
102
103       BodyContent JavaDoc bodyContent = getBodyContent();
104       if (bodyContent != null && bodyContent.getString() != null && bodyContent.getString().length() > 0)
105       {
106          sb.append(bodyContent.getString());
107          bodyContent.clearBody();
108       }
109       else
110       {
111          sb.append("<input type=\"checkbox\" name=\"").append(name).append("\" value=\"").append(value).append("\"/>");
112       }
113
114       sb.append(rowTag.getDisplayProvider().getCellPostProcess());
115       JspUtils.write(pageContext, sb.toString());
116
117       release();
118
119       return EVAL_PAGE;
120    }
121
122    /**
123     * @return Returns the property.
124     */

125    public String JavaDoc getProperty()
126    {
127       return this.property;
128    }
129
130    /**
131     * @param property The property to set.
132     */

133    public void setProperty(String JavaDoc property)
134    {
135       this.property = property;
136    }
137
138    /**
139     * @return Returns the name.
140     */

141    public String JavaDoc getName()
142    {
143       return this.name;
144    }
145
146    /**
147     * @param name The name to set.
148     */

149    public void setName(String JavaDoc name)
150    {
151       this.name = name;
152    }
153
154    private void reset()
155    {
156       this.name = null;
157       this.property = null;
158    }
159
160    /**
161     * Called on a Tag handler to release state.
162     * The page compiler guarantees that JSP page implementation
163     * objects will invoke this method on all tag handlers,
164     * but there may be multiple invocations on doStartTag and doEndTag in between.
165     *
166     * @see javax.servlet.jsp.tagext.Tag#release()
167     */

168    public void release()
169    {
170       super.release();
171       reset();
172    }
173 }
Popular Tags