KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > fr > improve > struts > taglib > layout > field > OptionTag


1 package fr.improve.struts.taglib.layout.field;
2
3 import javax.servlet.jsp.JspException JavaDoc;
4
5 import fr.improve.struts.taglib.layout.LabelledTag;
6 import fr.improve.struts.taglib.layout.el.Expression;
7 import fr.improve.struts.taglib.layout.util.LayoutUtils;
8 import fr.improve.struts.taglib.layout.util.TagUtils;
9
10 /**
11  * Tag used to add a value to a select or radios tag.
12  * Same syntax as the org.apache.struts.taglib.html.OptionTag.
13  *
14  * @author: Jean-NoŽl Ribette
15  */

16 public class OptionTag extends LabelledTag implements Choice {
17     /**
18      * Value of the option.
19      */

20     protected String JavaDoc value;
21     
22     /**
23      * Tooltip of the option
24      */

25     protected String JavaDoc tooltip;
26     
27     /**
28      * The computed label.
29      */

30     protected String JavaDoc choiceLabel;
31     
32     /**
33      * The computed tooltip.
34      */

35     protected String JavaDoc choiceTooltip;
36     
37     public int doEndLayoutTag() throws JspException JavaDoc {
38         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
39         if (key!=null) choiceLabel = getLabel(); else choiceLabel = value;
40         choiceTooltip = LayoutUtils.getLabel(pageContext, bundle, tooltip, null, false);
41         ChoiceTag choiceTag = (ChoiceTag) findAncestorWithClass(this, ChoiceTag.class);
42         if (choiceTag==null) {
43             throw new JspException JavaDoc("<layout:option> is not in a <layout:select> or <layout:radios> tag");
44         }
45         choiceTag.addChoice(buffer,this);
46         TagUtils.write(pageContext, buffer.toString());
47         return EVAL_PAGE;
48     }
49     public int doStartLayoutTag() {
50         return EVAL_BODY_INCLUDE;
51     }
52     public void release() {
53         super.release();
54         value = null;
55         tooltip = null;
56     }
57     public void setValue(String JavaDoc value) {
58         this.value = value;
59     }
60     public String JavaDoc getValue() {
61         return value;
62     }
63     public String JavaDoc getTooltip() {
64         return tooltip;
65     }
66     public void setTooltip(String JavaDoc tooltip) {
67         this.tooltip = tooltip;
68     }
69     
70     /**
71      * @see fr.improve.struts.taglib.layout.field.Choice#getChoiceLabel()
72      */

73     public String JavaDoc getChoiceLabel() {
74         return choiceLabel;
75     }
76     /**
77      * @see fr.improve.struts.taglib.layout.field.Choice#getChoiceTooltip()
78      */

79     public String JavaDoc getChoiceTooltip() {
80         return choiceTooltip;
81     }
82     /**
83      * @see fr.improve.struts.taglib.layout.field.Choice#getChoiceValue()
84      */

85     public String JavaDoc getChoiceValue() {
86         return Expression.evaluate(value, pageContext);
87     }
88 }
89
Popular Tags