1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package org.dbforms.taglib;
25
26 import java.util.HashMap;
27 import javax.servlet.jsp.JspException;
28 import javax.servlet.jsp.PageContext;
29
30 import org.apache.commons.logging.Log;
31 import org.apache.commons.logging.LogFactory;
32 import org.dbforms.util.ReflectionUtil;
33 import org.dbforms.util.Util;
34
35 import org.dbforms.interfaces.DbEventInterceptorData;
36 import org.dbforms.interfaces.IPresetFormValues;
37 import org.dbforms.interfaces.IAddProperty;
38
39 /***
40 *
41 * @author Henner Kollmann
42 *
43 * <db:presetFormValues class=""
44 */
45 public class PresetFormValuesTag extends AbstractScriptHandlerTag
46 implements IAddProperty, javax.servlet.jsp.tagext.TryCatchFinally {
47
48 private static final String sessionKey = "dbforms.org.tag.PresetFormValuesTag";
49 private static Log logCat = LogFactory.getLog(IsWebEventTag.class.getName());
50
51 private String className = null;
52
53 private HashMap properties = new HashMap();
54
55 /***
56 * classname of a class implementing the CustomFormatter Interface
57 *
58 * @param className
59 */
60 public void setClassName(String className) {
61 this.className = className;
62 }
63
64 public static void presetFormValues(DbEventInterceptorData data)
65 throws JspException {
66 PageContext pageContext = (PageContext) data
67 .getAttribute(DbEventInterceptorData.PAGECONTEXT);
68 if (pageContext != null) {
69 PresetFormValuesTag tag = (PresetFormValuesTag) pageContext
70 .getAttribute(sessionKey);
71 if (tag != null) {
72 tag.privatePresetFormValues(data);
73 }
74 }
75 }
76
77 public void privatePresetFormValues(DbEventInterceptorData data)
78 throws JspException {
79 if (!Util.isNull(className)) {
80 try {
81 IPresetFormValues cf = (IPresetFormValues) ReflectionUtil
82 .newInstance(className);
83 cf.presetFormValues(properties, data);
84 } catch (Exception e) {
85 logCat.error("privatePresetFormValues", e);
86 }
87 }
88 }
89
90 public int doStartTag() throws JspException {
91 properties.clear();
92 return super.doStartTag();
93 }
94
95 /***
96 * DOCUMENT ME!
97 *
98 * @return DOCUMENT ME!
99 */
100 public int doEndTag() throws JspException {
101 if (!Util.isNull(className)) {
102 pageContext.setAttribute(sessionKey, this);
103 }
104 return EVAL_PAGE;
105 }
106
107 /***
108 * DOCUMENT ME!
109 */
110 public void doFinally() {
111 super.doFinally();
112 }
113
114 public void addProperty(String name, String value) {
115 properties.put(name, value);
116 }
117
118 }