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