KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infoglue > cms > workflow > taglib > ContentBooleanFieldTag


1 /* ===============================================================================
2 *
3 * Part of the InfoGlue Content Management Platform (www.infoglue.org)
4 *
5 * ===============================================================================
6 *
7 * Copyright (C)
8 *
9 * This program is free software; you can redistribute it and/or modify it under
10 * the terms of the GNU General Public License version 2, as published by the
11 * Free Software Foundation. See the file LICENSE.html for more information.
12 *
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY, including the implied warranty of MERCHANTABILITY or FITNESS
15 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc. / 59 Temple
19 * Place, Suite 330 / Boston, MA 02111-1307 / USA.
20 *
21 * ===============================================================================
22 */

23
24 package org.infoglue.cms.workflow.taglib;
25
26 import javax.servlet.jsp.JspException JavaDoc;
27
28
29 /**
30  * Base class for tags presenting checkbox/radio form elements representing a content/content version attribute.
31  * The value of the content/content version attribute is fetched (with the name of the input element as a key)
32  * from the propertyset associated with the workflow.
33  */

34 public abstract class ContentBooleanFieldTag extends ElementTag
35 {
36     /**
37      * The form element value.
38      */

39     private String JavaDoc value;
40     
41     /**
42      * The value of the represented content/content version attribute.
43      */

44     private String JavaDoc checked;
45     
46     /**
47      * Default constructor.
48      */

49     public ContentBooleanFieldTag()
50     {
51         super();
52     }
53     
54     /**
55      * Process the end tag. Writes the element to the output stream.
56      *
57      * @return indication of whether to continue evaluating the JSP page.
58      * @throws JspException if an I/O error occurs when writing to the output stream.
59      */

60     public int doEndTag() throws JspException JavaDoc
61     {
62         getElement().addAttribute("checked", "checked", isChecked());
63         value = null;
64         checked = null;
65         return super.doEndTag();
66     }
67     
68     /**
69      * Returns true if the form element should be checked. That will
70      * be te case if the value of the represented attribute equals the value of the
71      * form element.
72      *
73      * @return true if the element should be checked; false otherwise.
74      */

75     private boolean isChecked()
76     {
77         return value != null && checked != null && value.equals(checked);
78     }
79     
80     /**
81      * Sets the name attribute of the input element.
82      *
83      * @param name the name to use.
84      */

85     public void setName(final String JavaDoc name)
86     {
87         getElement().addAttribute("name", name);
88         checked = getPropertySet().getDataString(name);
89     }
90
91     /**
92      * Sets the value attribute of the input element.
93      *
94      * @param value the value to use.
95      */

96     public void setValue(final String JavaDoc value)
97     {
98         getElement().addAttribute("value", value);
99         this.value = value;
100     }
101 }
Popular Tags