001 package org.apache.myfaces.tobago.taglib.component; 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.apt.annotation.Tag; 021 import org.apache.myfaces.tobago.apt.annotation.BodyContent; 022 import org.apache.myfaces.tobago.apt.annotation.TagAttribute; 023 import org.apache.myfaces.tobago.event.PopupActionListener; 024 025 import javax.servlet.jsp.tagext.TagSupport; 026 import javax.servlet.jsp.JspException; 027 import javax.faces.webapp.UIComponentTag; 028 import javax.faces.component.UIComponent; 029 import javax.faces.component.ActionSource; 030 031 /* 032 * Created by IntelliJ IDEA. 033 * User: bommel 034 * Date: Jan 3, 2007 035 * Time: 10:42:11 PM 036 */ 037 038 /** 039 * Register an PopupActionListener instance on the UIComponent 040 * associated with the closest parent UIComponent. 041 */ 042 @Tag(name = "popupReference", bodyContent = BodyContent.EMPTY) 043 public class PopupReferenceTag extends TagSupport { 044 045 private static final long serialVersionUID = -8444689365088370011L; 046 047 private String forComponent; 048 049 /** 050 * The id of a Popup. 051 */ 052 @TagAttribute 053 public void setFor(String popupId) { 054 this.forComponent = popupId; 055 } 056 057 public int doStartTag() throws JspException { 058 059 // Locate our parent UIComponentTag 060 UIComponentTag tag = 061 UIComponentTag.getParentUIComponentTag(pageContext); 062 if (tag == null) { 063 // TODO Message resource i18n 064 throw new JspException("Not nested in faces tag"); 065 } 066 067 if (!tag.getCreated()) { 068 return (SKIP_BODY); 069 } 070 071 UIComponent component = tag.getComponentInstance(); 072 if (component == null) { 073 // TODO Message resource i18n 074 throw new JspException("Component Instance is null"); 075 } 076 if (!(component instanceof ActionSource)) { 077 // TODO Message resource i18n 078 throw new JspException("Component "+ component.getClass().getName() + " is not instanceof ActionSource"); 079 } 080 ActionSource actionSource = (ActionSource) component; 081 actionSource.addActionListener(new PopupActionListener(forComponent)); 082 return (SKIP_BODY); 083 } 084 085 /** 086 * <p>Release references to any acquired resources. 087 */ 088 public void release() { 089 this.forComponent = null; 090 } 091 }