001: /*
002: * This file is part of the WfMOpen project.
003: * Copyright (C) 2001-2005 Danet GmbH (www.danet.de), BU BTS.
004: * All rights reserved.
005: *
006: * This program is free software; you can redistribute it and/or modify
007: * it under the terms of the GNU General Public License as published by
008: * the Free Software Foundation; either version 2 of the License, or
009: * (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: *
020: * This is based on the implementation of MyFaces.
021: *
022: * $Id: AttributeTag.java,v 1.3 2007/03/27 21:59:43 mlipp Exp $
023: *
024: * $Log: AttributeTag.java,v $
025: * Revision 1.3 2007/03/27 21:59:43 mlipp
026: * Fixed lots of checkstyle warnings.
027: *
028: * Revision 1.2 2006/09/29 12:32:09 drmlipp
029: * Consistently using WfMOpen as projct name now.
030: *
031: * Revision 1.1 2006/08/31 14:14:54 drmlipp
032: * Added attribute tag with late binding.
033: *
034: */
035: package de.danet.an.util.jsf.taglib;
036:
037: import javax.faces.component.UIComponent;
038: import javax.faces.context.FacesContext;
039: import javax.faces.el.ValueBinding;
040: import javax.faces.webapp.UIComponentTag;
041: import javax.servlet.jsp.JspException;
042: import javax.servlet.jsp.tagext.Tag;
043: import javax.servlet.jsp.tagext.TagSupport;
044:
045: /**
046: * This class provides an attribute with late binding. See
047: * http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5063023
048: */
049: public class AttributeTag extends TagSupport {
050:
051: private static final long serialVersionUID = -7931871116098202373L;
052:
053: private String _name;
054:
055: private String _value;
056:
057: public void setName(String name) {
058: _name = name;
059: }
060:
061: public void setValue(String value) {
062: _value = value;
063: }
064:
065: public int doStartTag() throws JspException {
066: UIComponentTag componentTag = UIComponentTag
067: .getParentUIComponentTag(pageContext);
068: if (componentTag == null) {
069: throw new JspException("no parent UIComponentTag found");
070: }
071: UIComponent component = componentTag.getComponentInstance();
072: if (component == null) {
073: throw new JspException(
074: "parent UIComponentTag has no UIComponent");
075: }
076: String name = getName();
077: if (component.getAttributes().get(name) == null) {
078: if (UIComponentTag.isValueReference(_value)) {
079: FacesContext facesContext = FacesContext
080: .getCurrentInstance();
081: ValueBinding vb = facesContext.getApplication()
082: .createValueBinding(_value);
083: component.setValueBinding(name, vb);
084: } else {
085: if (_value != null) {
086: component.getAttributes().put(name, _value);
087: }
088: }
089: }
090: return Tag.SKIP_BODY;
091: }
092:
093: public void release() {
094: super .release();
095: _name = null;
096: _value = null;
097: }
098:
099: private String getName() {
100: if (UIComponentTag.isValueReference(_name)) {
101: FacesContext facesContext = FacesContext
102: .getCurrentInstance();
103: ValueBinding vb = facesContext.getApplication()
104: .createValueBinding(_name);
105: return (String) vb.getValue(facesContext);
106: } else {
107: return _name;
108: }
109: }
110:
111: }
|