001    package org.apache.myfaces.tobago.event;
002    
003    /*
004     * Licensed to the Apache Software Foundation (ASF) under one or more
005     * contributor license agreements.  See the NOTICE file distributed with
006     * this work for additional information regarding copyright ownership.
007     * The ASF licenses this file to You under the Apache License, Version 2.0
008     * (the "License"); you may not use this file except in compliance with
009     * the License.  You may obtain a copy of the License at
010     *
011     *      http://www.apache.org/licenses/LICENSE-2.0
012     *
013     * Unless required by applicable law or agreed to in writing, software
014     * distributed under the License is distributed on an "AS IS" BASIS,
015     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016     * See the License for the specific language governing permissions and
017     * limitations under the License.
018     */
019    
020    import org.apache.myfaces.tobago.internal.util.FindComponentUtils;
021    import org.slf4j.Logger;
022    import org.slf4j.LoggerFactory;
023    
024    import javax.faces.component.StateHolder;
025    import javax.faces.component.UIComponent;
026    import javax.faces.component.UIComponentBase;
027    import javax.faces.context.FacesContext;
028    import javax.faces.el.ValueBinding;
029    import javax.faces.event.ActionEvent;
030    
031    public class ValueBindingPopupActionListener extends AbstractPopupActionListener implements StateHolder {
032    
033      private static final Logger LOG = LoggerFactory.getLogger(ValueBindingPopupActionListener.class);
034    
035      private ValueBinding popupIdBinding;
036    
037      public ValueBindingPopupActionListener(Object binding) {
038        popupIdBinding = (ValueBinding) binding;
039      }
040    
041      @Override
042      protected UIComponent getPopup(ActionEvent actionEvent) {
043        String id = (String) popupIdBinding.getValue(FacesContext.getCurrentInstance());
044        UIComponent popup = FindComponentUtils.findComponent(actionEvent.getComponent(), id);
045        if (popup == null) {
046          LOG.error("Found no popup for \""
047              + popupIdBinding.getExpressionString() + "\" := \""
048              + id + "\"! Search base componentId : "
049              + actionEvent.getComponent().getClientId(FacesContext.getCurrentInstance()));
050        }
051        return popup;
052      }
053    
054      public boolean isTransient() {
055        return false;
056      }
057    
058      public void restoreState(FacesContext context, Object state) {
059        Object[] values = (Object[]) state;
060        popupIdBinding = (ValueBinding) UIComponentBase.restoreAttachedState(context, values[0]);
061      }
062    
063      public Object saveState(FacesContext context) {
064        Object[] values = new Object[1];
065        values[0] = UIComponentBase.saveAttachedState(context, popupIdBinding);
066        return values;
067      }
068    
069    
070      public void setTransient(boolean newTransientValue) {
071        // ignore
072      }
073    }