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.component.UIPopup; 021 import org.apache.myfaces.tobago.component.ComponentUtil; 022 import org.apache.commons.logging.Log; 023 import org.apache.commons.logging.LogFactory; 024 025 import javax.faces.event.ActionListener; 026 import javax.faces.event.ActionEvent; 027 import javax.faces.event.AbortProcessingException; 028 import javax.faces.context.FacesContext; 029 import java.io.Serializable; 030 031 /* 032 * Date: Dec 23, 2006 033 * Time: 10:59:53 AM 034 */ 035 public class PopupActionListener implements ActionListener, Serializable { 036 037 private static final Log LOG = LogFactory.getLog(PopupActionListener.class); 038 039 private String popupId; 040 041 public PopupActionListener() { 042 } 043 044 public PopupActionListener(String popupId) { 045 this.popupId = popupId; 046 if (LOG.isDebugEnabled()) { 047 LOG.debug("Add ActionListener: " + popupId); 048 } 049 } 050 051 public PopupActionListener(UIPopup popup) { 052 this.popupId = ":" + popup.getClientId(FacesContext.getCurrentInstance()); 053 if (LOG.isDebugEnabled()) { 054 LOG.debug("Add ActionListener: " + popupId); 055 } 056 } 057 058 public void processAction(ActionEvent actionEvent) throws AbortProcessingException { 059 UIPopup popup = (UIPopup) ComponentUtil.findComponent(actionEvent.getComponent(), popupId); 060 061 if (popup != null) { 062 if (LOG.isDebugEnabled()) { 063 LOG.debug("activated " 064 + actionEvent.getComponent().getClientId(FacesContext.getCurrentInstance())); 065 } 066 popup.setActivated(true); 067 } else { 068 LOG.error("Found no popup for " + popupId); 069 } 070 } 071 072 }