001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License version 2
011: * as published by the Free Software Foundation.
012: *
013: * Resin Open Source is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
016: * of NON-INFRINGEMENT. See the GNU General Public License for more
017: * details.
018: *
019: * You should have received a copy of the GNU General Public License
020: * along with Resin Open Source; if not, write to the
021: *
022: * Free Software Foundation, Inc.
023: * 59 Temple Place, Suite 330
024: * Boston, MA 02111-1307 USA
025: *
026: * @author Scott Ferguson
027: */
028:
029: package javax.faces.webapp;
030:
031: import java.io.*;
032: import java.util.*;
033:
034: import javax.el.*;
035:
036: import javax.faces.*;
037: import javax.faces.application.*;
038: import javax.faces.component.*;
039: import javax.faces.context.*;
040: import javax.faces.el.*;
041: import javax.faces.event.*;
042: import javax.faces.render.*;
043:
044: import javax.servlet.jsp.*;
045: import javax.servlet.jsp.tagext.*;
046:
047: public abstract class UIComponentTag extends UIComponentClassicTagBase
048: implements Tag {
049: private ValueExpression _binding;
050: private ValueExpression _rendered;
051:
052: public void setBinding(String binding) throws JspException {
053: FacesContext context = FacesContext.getCurrentInstance();
054:
055: Application app = context.getApplication();
056: ExpressionFactory factory = app.getExpressionFactory();
057:
058: _binding = factory.createValueExpression(
059: context.getELContext(), binding, UIComponent.class);
060: }
061:
062: public boolean hasBinding() {
063: return _binding != null;
064: }
065:
066: public void setRendered(String rendered) throws JspException {
067: FacesContext context = FacesContext.getCurrentInstance();
068:
069: Application app = context.getApplication();
070: ExpressionFactory factory = app.getExpressionFactory();
071:
072: _rendered = factory.createValueExpression(context
073: .getELContext(), rendered, boolean.class);
074: }
075:
076: public boolean isSuppressed() {
077: return false;
078: }
079:
080: protected void setProperties(UIComponent component) {
081: if (_rendered != null)
082: component.setValueExpression("rendered", _rendered);
083:
084: String type = getRendererType();
085: if (type != null)
086: component.setRendererType(type);
087: }
088:
089: protected UIComponent createComponent(FacesContext context,
090: String newId) {
091: Application app = context.getApplication();
092:
093: UIComponent component;
094:
095: if (_binding != null) {
096: component = app.createComponent(_binding, context,
097: getComponentType());
098: component.setValueExpression("binding", _binding);
099: } else
100: component = app.createComponent(getComponentType());
101:
102: component.setId(getId());
103:
104: setProperties(component);
105:
106: return component;
107: }
108:
109: public static UIComponentTag getParentUIComponentTag(
110: PageContext context) {
111: UIComponentClassicTagBase parent;
112:
113: parent = getParentUIComponentClassicTagBase(context);
114:
115: return (UIComponentTag) parent;
116: }
117:
118: public static boolean isValueReference(String value) {
119: return value.startsWith("#{") && value.endsWith("}");
120: }
121: }
|