01: /*
02: * @author <a href="mailto:novotny@gridsphere.org">Jason Novotny</a>
03: * @author <a href="mailto:oliver.wehrens@aei.mpg.de">Oliver Wehrens</a>
04: * @version $Id: CheckboxTag.java 6385 2007-10-25 14:02:26Z wehrens $
05: */
06: package org.gridsphere.provider.portletui.tags;
07:
08: import org.gridsphere.provider.portletui.beans.CheckBoxBean;
09:
10: import javax.servlet.jsp.JspException;
11: import javax.servlet.jsp.JspWriter;
12:
13: /**
14: * A <code>CheckBoxTag</code> provides a checkbox element
15: */
16: public class CheckboxTag extends BaseComponentTag {
17:
18: protected CheckBoxBean checkbox = null;
19: protected boolean selected = false;
20: protected boolean selectSet = false;
21: protected String onClick = null;
22:
23: /**
24: * Sets the selected status of the bean
25: *
26: * @param flag status of the bean
27: */
28: public void setSelected(boolean flag) {
29: this .selected = flag;
30: this .selectSet = true;
31: }
32:
33: /**
34: * Returns the selected status of the bean
35: *
36: * @return selected status
37: */
38: public boolean isSelected() {
39: return selected;
40: }
41:
42: public String getOnClick() {
43: return onClick;
44: }
45:
46: public void setOnClick(String onClick) {
47: this .onClick = onClick;
48: }
49:
50: public int doStartTag() throws JspException {
51: if (!beanId.equals("")) {
52: checkbox = (CheckBoxBean) getTagBean();
53: if (checkbox == null) {
54: checkbox = new CheckBoxBean();
55: checkbox.setSelected(selected);
56: this .setBaseComponentBean(checkbox);
57: } else {
58: this .setBaseComponentBean(checkbox);
59: }
60: } else {
61: checkbox = new CheckBoxBean();
62: this .setBaseComponentBean(checkbox);
63: }
64: if (selectSet)
65: checkbox.setSelected(selected);
66: if (onClick != null)
67: checkbox.setOnClick(onClick);
68:
69: try {
70: JspWriter out = pageContext.getOut();
71: out.print(checkbox.toStartString());
72: } catch (Exception e) {
73: throw new JspException(e.getMessage());
74: }
75: return SKIP_BODY;
76: }
77:
78: }
|