001: /*
002: * Copyright 2005 The Apache Software Foundation.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.apache.myfaces.taglib.core;
018:
019: import javax.el.ValueExpression;
020: import javax.faces.component.ActionSource;
021: import javax.faces.component.UIComponent;
022: import javax.faces.event.ActionListener;
023: import javax.faces.webapp.UIComponentClassicTagBase;
024: import javax.servlet.jsp.JspException;
025: import javax.servlet.jsp.tagext.TagSupport;
026:
027: import org.apache.commons.logging.Log;
028: import org.apache.commons.logging.LogFactory;
029:
030: import org.apache.myfaces.event.SetPropertyActionListener;
031:
032: /**
033: * @author Dennis Byrne
034: * @since 1.2
035: */
036:
037: public class SetPropertyActionListenerTag extends TagSupport {
038:
039: private static final Log log = LogFactory
040: .getLog(SetPropertyActionListenerTag.class);
041:
042: private ValueExpression target;
043:
044: private ValueExpression value;
045:
046: public int doStartTag() throws JspException {
047:
048: if (log.isDebugEnabled())
049: log
050: .debug("JSF 1.2 Spec : Create a new instance of the ActionListener");
051:
052: ActionListener actionListener = new SetPropertyActionListener(
053: target, value);
054:
055: UIComponentClassicTagBase tag = UIComponentClassicTagBase
056: .getParentUIComponentClassicTagBase(pageContext);
057:
058: if (tag == null)
059: throw new JspException("Could not find a "
060: + "parent UIComponentClassicTagBase ... is this "
061: + "tag in a child of a UIComponentClassicTagBase?");
062:
063: if (tag.getCreated()) {
064:
065: UIComponent component = tag.getComponentInstance();
066:
067: if (component == null)
068: throw new JspException(
069: " Could not locate a UIComponent "
070: + "for a UIComponentClassicTagBase w/ a "
071: + "JSP id of " + tag.getJspId());
072:
073: if (!(component instanceof ActionSource))
074: throw new JspException("Component w/ id of "
075: + component.getId()
076: + " is associated w/ a tag w/ JSP id of "
077: + tag.getJspId()
078: + ". This component is of type "
079: + component.getClass() + ", which is not an "
080: + ActionSource.class);
081:
082: if (log.isDebugEnabled())
083: log
084: .debug(" ... register it with the UIComponent "
085: + "instance associated with our most immediately "
086: + "surrounding UIComponentTagBase");
087:
088: ((ActionSource) component)
089: .addActionListener(actionListener);
090:
091: }
092:
093: return SKIP_BODY;
094: }
095:
096: public ValueExpression getTarget() {
097: return target;
098: }
099:
100: public void setTarget(ValueExpression target) {
101: this .target = target;
102: }
103:
104: public ValueExpression getValue() {
105: return value;
106: }
107:
108: public void setValue(ValueExpression value) {
109: this .value = value;
110: }
111:
112: public void release() {
113: target = null;
114: value = null;
115: }
116:
117: }
|