KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > fr > improve > struts > taglib > layout > field > ajax > select > SelectDependentTag


1 package fr.improve.struts.taglib.layout.field.ajax.select;
2
3 import javax.servlet.jsp.JspException JavaDoc;
4
5 import fr.improve.struts.taglib.layout.field.SelectTag;
6 import fr.improve.struts.taglib.layout.util.LayoutUtils;
7 import fr.improve.struts.taglib.layout.util.TagUtils;
8
9 /**
10  * allows to create double-combo linked list with Ajax.
11  * @author nsoule
12  *
13  */

14 public class SelectDependentTag extends SelectTag {
15     
16     /**
17      * The second selection list name (target).
18      */

19     protected String JavaDoc targetName;
20     /**
21      * The struts action instance to which we are attached.
22      */

23     protected String JavaDoc fillDropDownAction;
24     
25     /**
26      * Indicate if we have double-combo linked list.
27      */

28     protected String JavaDoc doubleCombo;
29         
30     public static final String JavaDoc LOADED = "fr.improve.struts.taglib.layout.field.ajax.select.SelectDependentTag.LOADED";
31
32     /* (non-Javadoc)
33      * @see fr.improve.struts.taglib.layout.field.SelectTag#doBeforeValue()
34      */

35     protected boolean doBeforeValue() throws JspException JavaDoc {
36         
37         if (doubleCombo != null && doubleCombo.equals("true")) {
38             loadScript();
39         }
40         return super.doBeforeValue();
41     }
42         
43     /**
44      * Load the required Javascript code.
45      */

46     protected void loadScript() throws JspException JavaDoc {
47         
48         if (pageContext.getRequest().getAttribute(LOADED)==null) {
49             TagUtils.write(pageContext, "<script SRC=\"");
50             TagUtils.write(pageContext, LayoutUtils.getSkin(pageContext.getSession()).getConfigDirectory(pageContext.getRequest()));
51             TagUtils.write(pageContext, "/selectDependent.js\"></script>");
52             pageContext.getRequest().setAttribute(LOADED, "");
53         }
54     }
55
56     /**
57      * @return Returns the fillDropDownAction.
58      */

59     public String JavaDoc getFillDropDownAction() {
60         return fillDropDownAction;
61     }
62
63     /**
64      * @param fillDropDownAction The fillDropDownAction to set.
65      */

66     public void setFillDropDownAction(String JavaDoc fillDropDownAction) {
67         this.fillDropDownAction = fillDropDownAction;
68     }
69
70
71     /**
72      * @return Returns the targetName.
73      */

74     public String JavaDoc getTargetName() {
75         return targetName;
76     }
77
78     /**
79      * @param targetName The targetName to set.
80      */

81     public void setTargetName(String JavaDoc targetName) {
82         this.targetName = targetName;
83     }
84
85     /**
86      * @return Returns the doubleCombo.
87      */

88     public String JavaDoc getDoubleCombo() {
89         return doubleCombo;
90     }
91
92
93     /**
94      * @param doubleCombo The doubleCombo to set.
95      */

96     public void setDoubleCombo(String JavaDoc doubleCombo) {
97         this.doubleCombo = doubleCombo;
98     }
99
100     /* (non-Javadoc)
101      * @see fr.improve.struts.taglib.layout.field.AbstractFieldTag#initDynamicValues()
102      */

103     protected void initDynamicValues() {
104         super.initDynamicValues();
105         
106         String JavaDoc url = null;
107
108         try {
109             url = LayoutUtils.computeURL(pageContext, null, null, null,
110                                          this.getFillDropDownAction(), null, null,
111                                          null, false, "");
112         }
113         catch (JspException JavaDoc e) {
114             TagUtils.saveException(pageContext, e);
115             throw new RuntimeException JavaDoc(e.getMessage());
116         }
117                 
118         if (doubleCombo != null && doubleCombo.equals("true")) {
119             onchange =(onchange != null ? (onchange +";") : "")
120                       + "updateDropDownList(this,'"+ getName() +"', '"
121                       + getTargetName() + "', '" + url + "' )";
122         }
123     }
124
125     /* (non-Javadoc)
126      * @see fr.improve.struts.taglib.layout.field.SelectTag#reset()
127      */

128     protected void reset() {
129         super.reset();
130         onchange = null;
131         onkeypress = null;
132         targetName = null;
133         fillDropDownAction = null;
134         doubleCombo = null;
135     }
136     
137
138 }
139
Popular Tags