View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
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.faces.component.StateHolder;
29  import javax.faces.component.UIComponent;
30  import javax.faces.component.UIComponentBase;
31  import javax.faces.context.FacesContext;
32  import javax.faces.el.ValueBinding;
33  import javax.faces.event.ActionEvent;
34  
35  
36  /**
37   * @deprecated Since 2.0.0, please use ValueExpressionResetInputActionListener
38   */
39  @Deprecated
40  public class ValueBindingResetInputActionListener extends AbstractResetInputActionListener implements StateHolder {
41    private static final Logger LOG = LoggerFactory.getLogger(ValueBindingResetInputActionListener.class);
42  
43    private ValueBinding clientIdsBinding;
44  
45    /**
46     * No-arg constructor used during restoreState
47     */
48    public ValueBindingResetInputActionListener() {
49    }
50  
51    public ValueBindingResetInputActionListener(Object binding) {
52      clientIdsBinding = (ValueBinding) binding;
53    }
54  
55    public void processAction(ActionEvent event) {
56      Object obj = clientIdsBinding.getValue(FacesContext.getCurrentInstance());
57      String [] clientIds;
58      if (obj instanceof String[]) {
59        clientIds = (String[]) obj;
60      } else if (obj instanceof String) {
61        clientIds= StringUtils.split((String) obj, ", ");
62      } else {
63        LOG.error("Ignore unknown value of " + obj + " for reset.");
64        return;
65      }
66      for (String clientId : clientIds) {
67        UIComponent component = FindComponentUtils.findComponent(event.getComponent(), clientId);
68        if (component != null) {
69          resetChildren(component);
70        }
71      }
72    }
73  
74    public boolean isTransient() {
75      return false;
76    }
77  
78    public void restoreState(FacesContext context, Object state) {
79      Object[] values = (Object[]) state;
80      clientIdsBinding = (ValueBinding) UIComponentBase.restoreAttachedState(context, values[0]);
81    }
82  
83    public Object saveState(FacesContext context) {
84      Object[] values = new Object[1];
85      values[0] = UIComponentBase.saveAttachedState(context, clientIdsBinding);
86      return values;
87    }
88  
89    public void setTransient(boolean newTransientValue) {
90      // ignore
91    }
92  
93  }