1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.myfaces.tobago.internal.taglib.component;
21
22 import org.apache.myfaces.tobago.apt.annotation.BodyContent;
23 import org.apache.myfaces.tobago.apt.annotation.Tag;
24 import org.apache.myfaces.tobago.apt.annotation.TagAttribute;
25 import org.apache.myfaces.tobago.apt.annotation.TagGeneration;
26 import org.apache.myfaces.tobago.component.Attributes;
27 import org.apache.myfaces.tobago.event.ResetFormActionListener;
28 import org.apache.myfaces.tobago.event.ResetInputActionListener;
29 import org.apache.myfaces.tobago.event.ValueExpressionResetInputActionListener;
30 import org.apache.myfaces.tobago.util.ComponentUtils;
31
32 import javax.el.ELContext;
33 import javax.el.ValueExpression;
34 import javax.faces.component.ActionSource;
35 import javax.faces.component.UIComponent;
36 import javax.faces.context.FacesContext;
37 import javax.faces.webapp.UIComponentClassicTagBase;
38 import javax.faces.webapp.UIComponentELTag;
39 import javax.servlet.jsp.JspException;
40 import javax.servlet.jsp.tagext.TagSupport;
41
42
43
44
45
46 @Tag(name = "resetInputActionListener", bodyContent = BodyContent.EMPTY)
47 @TagGeneration(className = "org.apache.myfaces.tobago.internal.taglib.ResetInputActionListenerTag")
48 public abstract class ResetInputActionListenerTag extends TagSupport {
49
50 private static final long serialVersionUID = 2L;
51
52 private ValueExpression execute;
53
54 public int doStartTag() throws JspException {
55
56
57 UIComponentClassicTagBase tag =
58 UIComponentELTag.getParentUIComponentClassicTagBase(pageContext);
59 if (tag == null) {
60
61 throw new JspException("Not nested in faces tag");
62 }
63
64 if (!tag.getCreated()) {
65 return (SKIP_BODY);
66 }
67
68 UIComponent component = tag.getComponentInstance();
69 if (component == null) {
70
71 throw new JspException("Component Instance is null");
72 }
73 if (!(component instanceof ActionSource)) {
74
75 throw new JspException("Component " + component.getClass().getName() + " is not instanceof ActionSource");
76 }
77
78 final ELContext elContext = FacesContext.getCurrentInstance().getELContext();
79
80 ActionSource actionSource = (ActionSource) component;
81 if (execute == null) {
82 actionSource.addActionListener(new ResetFormActionListener());
83 } else if (execute.isLiteralText()) {
84 actionSource.addActionListener(new ResetInputActionListener(
85 ComponentUtils.splitList((String) execute.getValue(elContext))));
86 } else {
87 actionSource.addActionListener(new ValueExpressionResetInputActionListener(execute));
88 }
89 return (SKIP_BODY);
90 }
91
92 @Override
93 public void release() {
94 super.release();
95 execute = null;
96 }
97
98
99
100
101
102 @TagAttribute(required = false, name = Attributes.EXECUTE, type = "java.lang.String")
103 public void setExecute(javax.el.ValueExpression execute) {
104 this.execute = execute;
105 }
106
107 }