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