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  import org.apache.myfaces.tobago.internal.component.AbstractUIPopup;
23  import org.apache.myfaces.tobago.util.ComponentUtils;
24  import org.slf4j.Logger;
25  import org.slf4j.LoggerFactory;
26  
27  import javax.faces.component.StateHolder;
28  import javax.faces.component.UIComponent;
29  import javax.faces.component.UIComponentBase;
30  import javax.faces.context.FacesContext;
31  import javax.faces.el.ValueBinding;
32  import javax.faces.event.ActionEvent;
33  
34  /**
35   * @deprecated Since 2.0.0, please use ValueExpressionPopupActionListener
36   */
37  @Deprecated
38  public class ValueBindingPopupActionListener extends AbstractPopupActionListener implements StateHolder {
39  
40    private static final Logger LOG = LoggerFactory.getLogger(ValueBindingPopupActionListener.class);
41  
42    private ValueBinding popupIdBinding;
43  
44    /**
45     * No-arg constructor used during restoreState
46     */
47    public ValueBindingPopupActionListener() {
48    }
49  
50    public ValueBindingPopupActionListener(final Object binding) {
51      popupIdBinding = (ValueBinding) binding;
52    }
53  
54    @Override
55    protected AbstractUIPopup getPopup(final ActionEvent actionEvent) {
56      final String id = (String) popupIdBinding.getValue(FacesContext.getCurrentInstance());
57      final UIComponent popup = ComponentUtils.findComponent(actionEvent.getComponent(), id);
58      if (popup instanceof AbstractUIPopup) {
59        return (AbstractUIPopup) popup;
60      } else {
61        LOG.error("Found no popup for \""
62            + popupIdBinding.getExpressionString() + "\" := \""
63            + id + "\"! Search base componentId : "
64            + actionEvent.getComponent().getClientId(FacesContext.getCurrentInstance()));
65        return null;
66      }
67    }
68  
69    public boolean isTransient() {
70      return false;
71    }
72  
73    public void restoreState(final FacesContext context, final Object state) {
74      final Object[] values = (Object[]) state;
75      popupIdBinding = (ValueBinding) UIComponentBase.restoreAttachedState(context, values[0]);
76    }
77  
78    public Object saveState(final FacesContext context) {
79      final Object[] values = new Object[1];
80      values[0] = UIComponentBase.saveAttachedState(context, popupIdBinding);
81      return values;
82    }
83  
84  
85    public void setTransient(final boolean newTransientValue) {
86      // ignore
87    }
88  }