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.facelets;
21
22 import org.apache.myfaces.tobago.component.Attributes;
23 import org.apache.myfaces.tobago.event.ResetFormActionListener;
24 import org.apache.myfaces.tobago.event.ResetInputActionListener;
25 import org.apache.myfaces.tobago.event.ValueExpressionResetInputActionListener;
26 import org.apache.myfaces.tobago.util.ComponentUtils;
27
28 import javax.el.ELException;
29 import javax.el.ValueExpression;
30 import javax.faces.FacesException;
31 import javax.faces.component.ActionSource;
32 import javax.faces.component.UIComponent;
33 import javax.faces.view.facelets.ComponentHandler;
34 import javax.faces.view.facelets.FaceletContext;
35 import javax.faces.view.facelets.TagAttribute;
36 import javax.faces.view.facelets.TagConfig;
37 import javax.faces.view.facelets.TagException;
38 import javax.faces.view.facelets.TagHandler;
39 import java.io.IOException;
40
41 public class ResetInputActionListenerHandler extends TagHandler {
42
43 private final TagAttribute execute;
44
45 public ResetInputActionListenerHandler(TagConfig config) {
46 super(config);
47 execute = getAttribute(Attributes.EXECUTE);
48 }
49
50 public void apply(FaceletContext faceletContext, UIComponent parent)
51 throws IOException, FacesException, ELException {
52 if (parent instanceof ActionSource) {
53 if (ComponentHandler.isNew(parent)) {
54 ActionSource actionSource = (ActionSource) parent;
55 if (execute == null) {
56 actionSource.addActionListener(new ResetFormActionListener());
57 } else if (execute.isLiteral()) {
58 actionSource.addActionListener(new ResetInputActionListener(ComponentUtils.splitList(execute.getValue())));
59 } else {
60 ValueExpression forValueExpression = execute.getValueExpression(faceletContext, String.class);
61 actionSource.addActionListener(new ValueExpressionResetInputActionListener(forValueExpression));
62 }
63 }
64 } else {
65 throw new TagException(tag, "Parent is not of type ActionSource, type is: " + parent);
66 }
67 }
68 }
69
70