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: RadioButtonTag.java 6419 2008-02-08 12:14:21Z docentt $
05: */
06: package org.gridsphere.provider.portletui.tags;
07:
08: import org.gridsphere.provider.portletui.beans.RadioButtonBean;
09:
10: import javax.servlet.jsp.JspException;
11: import javax.servlet.jsp.JspWriter;
12: import java.util.List;
13:
14: /**
15: * A <code>RadioButtonTag</code> represents a radio button element
16: */
17: public class RadioButtonTag extends BaseComponentTag {
18:
19: protected RadioButtonBean radiobutton = null;
20: protected boolean selected = 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: }
31:
32: /**
33: * Returns the selected status of the bean
34: *
35: * @return selected status
36: */
37: public boolean isSelected() {
38: return selected;
39: }
40:
41: public String getOnClick() {
42: return onClick;
43: }
44:
45: public void setOnClick(String onClick) {
46: this .onClick = onClick;
47: }
48:
49: public int doStartTag() throws JspException {
50:
51: if (!beanId.equals("")) {
52: radiobutton = (RadioButtonBean) getTagBean();
53: if (radiobutton == null) {
54: radiobutton = new RadioButtonBean();
55: this .setBaseComponentBean(radiobutton);
56: } else {
57: this .setBaseComponentBean(radiobutton);
58: //this.updateBaseComponentBean(radiobutton);
59: //this.overrideBaseComponentBean(radiobutton);
60: }
61: List vals = radiobutton.getSelectedValues();
62: if (vals.contains(value)) {
63: radiobutton.setSelected(true);
64: } else {
65: //if (!selected) selected = radiobutton.isSelected();
66: if (vals.isEmpty())
67: radiobutton.setSelected(selected);
68: }
69:
70: } else {
71: radiobutton = new RadioButtonBean();
72: radiobutton.setSelected(selected);
73: this .setBaseComponentBean(radiobutton);
74: }
75:
76: if (onClick != null)
77: radiobutton.setOnClick(onClick);
78:
79: //debug();
80:
81: try {
82: JspWriter out = pageContext.getOut();
83: out.print(radiobutton.toStartString());
84: //GPF-114 fix
85: if (radiobutton.isSelected())
86: radiobutton.setSelected(false);
87: } catch (Exception e) {
88: throw new JspException(e.getMessage());
89: }
90:
91: return SKIP_BODY;
92: }
93:
94: }
|