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.event;
21
22
23 import org.apache.commons.lang.StringUtils;
24 import org.apache.myfaces.tobago.internal.util.FindComponentUtils;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
27
28 import javax.el.ValueExpression;
29 import javax.faces.component.StateHolder;
30 import javax.faces.component.UIComponent;
31 import javax.faces.component.UIComponentBase;
32 import javax.faces.context.FacesContext;
33 import javax.faces.event.ActionEvent;
34
35 public class ValueExpressionResetInputActionListener extends AbstractResetInputActionListener implements StateHolder {
36
37 private static final Logger LOG = LoggerFactory.getLogger(ValueExpressionResetInputActionListener.class);
38
39 private ValueExpression clientIdsExpression;
40
41
42
43
44 public ValueExpressionResetInputActionListener() {
45 }
46
47 public ValueExpressionResetInputActionListener(ValueExpression clientIdsExpression) {
48 this.clientIdsExpression = clientIdsExpression;
49 }
50
51 public void processAction(ActionEvent event) {
52 Object obj = clientIdsExpression.getValue(FacesContext.getCurrentInstance().getELContext());
53 String [] clientIds;
54 if (obj instanceof String[]) {
55 clientIds = (String[]) obj;
56 } else if (obj instanceof String) {
57 clientIds= StringUtils.split((String) obj, ", ");
58 } else {
59 LOG.error("Ignore unknown value of " + obj + " for reset.");
60 return;
61 }
62 for (String clientId : clientIds) {
63 UIComponent component = FindComponentUtils.findComponent(event.getComponent(), clientId);
64 if (component != null) {
65 resetChildren(component);
66 }
67 }
68 }
69
70 public boolean isTransient() {
71 return false;
72 }
73
74 public void restoreState(FacesContext context, Object state) {
75 Object[] values = (Object[]) state;
76 clientIdsExpression = (ValueExpression) UIComponentBase.restoreAttachedState(context, values[0]);
77 }
78
79 public Object saveState(FacesContext context) {
80 Object[] values = new Object[1];
81 values[0] = UIComponentBase.saveAttachedState(context, clientIdsExpression);
82 return values;
83 }
84
85
86 public void setTransient(boolean newTransientValue) {
87
88 }
89
90 }