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.el.ValueExpression; 025 import javax.faces.component.StateHolder; 026 import javax.faces.component.UIComponent; 027 import javax.faces.component.UIComponentBase; 028 import javax.faces.context.FacesContext; 029 import javax.faces.event.ActionEvent; 030 031 032 public class ValueExpressionPopupActionListener extends AbstractPopupActionListener implements StateHolder { 033 034 private static final Logger LOG = LoggerFactory.getLogger(ValueExpressionPopupActionListener.class); 035 036 private ValueExpression popupIdExpression; 037 038 public ValueExpressionPopupActionListener(Object expression) { 039 popupIdExpression = (ValueExpression) expression; 040 } 041 042 @Override 043 protected UIComponent getPopup(ActionEvent actionEvent) { 044 String id = (String) popupIdExpression.getValue(FacesContext.getCurrentInstance().getELContext()); 045 UIComponent popup = FindComponentUtils.findComponent(actionEvent.getComponent(), id); 046 if (popup == null) { 047 LOG.error("Found no popup for \"" 048 + popupIdExpression.getExpressionString() + "\" := \"" 049 + id + "\"! Search base componentId : " 050 + actionEvent.getComponent().getClientId(FacesContext.getCurrentInstance())); 051 } 052 return popup; 053 } 054 055 public boolean isTransient() { 056 return false; 057 } 058 059 public void restoreState(FacesContext context, Object state) { 060 Object[] values = (Object[]) state; 061 popupIdExpression = (ValueExpression) UIComponentBase.restoreAttachedState(context, values[0]); 062 } 063 064 public Object saveState(FacesContext context) { 065 Object[] values = new Object[1]; 066 values[0] = UIComponentBase.saveAttachedState(context, popupIdExpression); 067 return values; 068 } 069 070 071 public void setTransient(boolean newTransientValue) { 072 // ignore 073 } 074 }