You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ba...@apache.org on 2006/10/10 21:49:23 UTC
svn commit: r462531 [2/2] - in /myfaces:
core/branches/jsf12/api/src/main/java/javax/faces/webapp/
shared/branches/3_0_0/
shared/branches/3_0_0/core/src/main/java/org/apache/myfaces/shared/taglib/
Modified: myfaces/core/branches/jsf12/api/src/main/java/javax/faces/webapp/UIComponentTag.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/jsf12/api/src/main/java/javax/faces/webapp/UIComponentTag.java?view=diff&rev=462531&r1=462530&r2=462531
==============================================================================
--- myfaces/core/branches/jsf12/api/src/main/java/javax/faces/webapp/UIComponentTag.java (original)
+++ myfaces/core/branches/jsf12/api/src/main/java/javax/faces/webapp/UIComponentTag.java Tue Oct 10 12:49:22 2006
@@ -50,39 +50,23 @@
* officially required behaviour, though it is believed that this class
* does comply with the specification.
*
- * see Javadoc of <a href="http://java.sun.com/j2ee/javaserverfaces/1.1_01/docs/api/index.html">JSF Specification</a> for more.
+ * see Javadoc of <a href="http://java.sun.com/j2ee/javaserverfaces/1.2/docs/api/index.html">JSF Specification</a> for more.
*
* @author Manfred Geiler (latest modification by $Author$)
+ * @author Bruno Aranda
* @version $Revision$ $Date$
*
* @deprecated replaced by {@link UIComponentELTag}
*/
-public abstract class UIComponentTag
- implements Tag
+public abstract class UIComponentTag extends UIComponentClassicTagBase
{
- private static final String FORMER_CHILD_IDS_SET_ATTR = UIComponentTag.class.getName() + ".FORMER_CHILD_IDS";
- private static final String FORMER_FACET_NAMES_SET_ATTR = UIComponentTag.class.getName() + ".FORMER_FACET_NAMES";
-
- // do not change this w/out doing likewise in UIComponentClassicTagBase
- private static final String COMPONENT_STACK_ATTR = "org.apache.myfaces.COMPONENT_STACK";
-
- private static final String UNIQUE_ID_COUNTER_ATTR = UIComponentTag.class.getName() + ".UNIQUE_ID_COUNTER";
-
- protected PageContext pageContext = null;
- private Tag _parent = null;
//tag attributes
private String _binding = null;
- private String _id = null;
private String _rendered = null;
- private FacesContext _facesContext = null;
- private UIComponent _componentInstance = null;
- private boolean _created = false;
private Boolean _suppressed = null;
private ResponseWriter _writer = null;
- private Set _childrenAdded = null;
- private Set _facetsAdded = null;
private static Log log = LogFactory.getLog(UIComponentTag.class);
@@ -94,39 +78,12 @@
public void release()
{
- internalRelease();
+ super.release();
- //members, that must/need only be reset when there is no more risk, that the container
- //wants to reuse this tag
- pageContext = null;
- _parent = null;
-
- // Reset tag attribute members. These are reset here rather than in
- // internalRelease because of some Resin-related issue. See commit
- // r166747.
_binding = null;
- _id = null;
_rendered = null;
}
-
- /**
- * Reset any members that apply to the according component instance and
- * must not be reused if the container wants to reuse this tag instance.
- * This method is called when rendering for this tag is finished
- * ( doEndTag() ) or when released by the container.
- */
- private void internalRelease()
- {
- _facesContext = null;
- _componentInstance = null;
- _created = false;
- _suppressed = null;
- _writer = null;
- _childrenAdded = null;
- _facetsAdded = null;
- }
-
/** Setter for common JSF xml attribute "binding". */
public void setBinding(String binding)
throws JspException
@@ -138,19 +95,6 @@
_binding = binding;
}
- /** Setter for common JSF xml attribute "id". */
- public void setId(String id)
- {
- _id = id;
- }
-
- /**
- * Return the id (if any) specified as an xml attribute on this tag.
- */
- protected String getId()
- {
- return _id;
- }
/** Setter for common JSF xml attribute "rendered". */
public void setRendered(String rendered)
@@ -158,34 +102,6 @@
_rendered = rendered;
}
- /**
- * Specify the "component type name" used together with the component's
- * family and the Application object to create a UIComponent instance for
- * this tag. This method is called by other methods in this class, and is
- * intended to be overridden in subclasses to specify the actual component
- * type to be created.
- *
- * @return a registered component type name, never null.
- */
- public abstract String getComponentType();
-
- /**
- * Return the UIComponent instance associated with this tag.
- * @return a UIComponent, never null.
- */
- public UIComponent getComponentInstance()
- {
- return _componentInstance;
- }
-
- /**
- * Return true if this tag created the associated UIComponent (rather
- * than locating an existing instance of the UIComponent in the view).
- */
- public boolean getCreated()
- {
- return _created;
- }
/**
* Return the nearest JSF tag that encloses this tag.
@@ -193,45 +109,19 @@
*/
public static UIComponentTag getParentUIComponentTag(PageContext pageContext)
{
- Stack stack = getStack(pageContext);
-
- int size = stack.size();
-
- return size > 1 ? (UIComponentTag)stack.get(size - 1) : null;
- }
+ UIComponentClassicTagBase parentTag = getParentUIComponentClassicTagBase(pageContext);
- /**
- * The pageContext's request scope map is used to hold a stack of
- * JSP tag objects seen so far, so that a new tag can find the
- * parent tag that encloses it. Access to the parent tag is used
- * to find the parent UIComponent for the component associated
- * with this tag plus some other uses.
- */
-
- private void popTag()
- {
- Stack stack = getStack(pageContext);
-
- int size = stack.size();
- stack.remove(size -1);
- if (size <= 1)
- pageContext.removeAttribute(COMPONENT_STACK_ATTR,
- PageContext.REQUEST_SCOPE);
-
+ if (parentTag instanceof UIComponentTag)
+ {
+ return (UIComponentTag) parentTag;
+ }
+ else
+ {
+ return new UIComponentTagWrapper(parentTag);
+ }
}
/**
- * Specify the "renderer type name" used together with the current
- * renderKit to get a Renderer instance for the corresponding UIComponent.
- * <p>
- * A JSP tag can return null here to use the default renderer type string.
- * If non-null is returned, then the UIComponent's setRendererType method
- * will be called passing this value, and this will later affect the
- * type of renderer object returned by UIComponent.getRenderer().
- */
- public abstract String getRendererType();
-
- /**
* Return true if the specified string contains an EL expression.
* <p>
* UIComponent properties are often required to be value-binding
@@ -250,435 +140,13 @@
}
/**
- * Standard method invoked by the JSP framework to inform this tag
- * of the PageContext associated with the jsp page currently being
- * processed.
- */
- public void setPageContext(PageContext pageContext)
- {
- this.pageContext = pageContext;
- }
-
- /**
- * Returns the enclosing JSP tag object. Note that this is not
- * necessarily a JSF tag.
- */
- public Tag getParent()
- {
- return _parent;
- }
-
- /**
- * Standard method invoked by the JSP framework to inform this tag
- * of the enclosing JSP tag object.
- */
- public void setParent(Tag parent)
- {
- _parent = parent;
- }
-
- /**
- * Invoked by the standard jsp processing mechanism when the opening
- * tag of a JSF component element is found.
- * <p>
- * The UIComponent associated with this tag is created (if the view
- * doesn't exist) or located if the view is being re-rendered. If
- * the component is not "suppressed" then its encodeBegin method is
- * called (see method isSuppressed). Note also that method
- * encodeBegin is <i>not</i> called for components for which
- * getRendersChildren returns true; that occurs only in doEndTag.
- */
- public int doStartTag()
- throws JspException
- {
- setupResponseWriter();
- FacesContext facesContext = getFacesContext();
- UIComponent component = findComponent(facesContext);
- if (!component.getRendersChildren() && !isSuppressed())
- {
- try
- {
- encodeBegin();
- _writer.flush();
- }
- catch (IOException e)
- {
- throw new JspException(e.getMessage(), e);
- }
- }
- getStack(pageContext).add(this); // push this tag on the stack
- return getDoStartValue();
- }
-
- /**
- * Invoked by the standard jsp processing mechanism when the closing
- * tag of a JSF component element is found.
- * <p>
- * When the view is being re-rendered, any former children of this tag's
- * corresponding component which do not have corresponding tags
- * as children of this tag are removed from the view. This isn't likely
- * to be a common occurrence: wrapping JSF tags in JSTL tag "c:if" is
- * one possible cause. Programmatically created components are not affected
- * by this.
- * <p>
- * If the corresponding component returns true from getRendersChildren
- * then its encodeBegin and encodeChildren methods are called here.
- * <p>
- * The component's encodeEnd method is called provided the component
- * is not "suppressed".
- */
- public int doEndTag()
- throws JspException
- {
- popTag();
- UIComponent component = getComponentInstance();
- removeFormerChildren(component);
- removeFormerFacets(component);
-
- try
- {
- if (!isSuppressed())
- {
- if (component.getRendersChildren())
- {
- encodeBegin();
- encodeChildren();
- }
- encodeEnd();
- }
- }
- catch (IOException e)
- {
- throw new JspException(e.getMessage(), e);
- }
-
- int retValue = getDoEndValue();
- internalRelease();
- return retValue;
- }
-
- /**
- * Remove any child components of the associated components which do not
- * have corresponding tags as children of this tag. This only happens
- * when a view is being re-rendered and there are components in the view
- * tree which don't have corresponding JSP tags. Wrapping JSF tags in
- * JSTL "c:if" statements is one way this can happen.
- * <br />
- * Attention: programmatically added components are are not affected by this:
- * they will not be on the old list of created components nor on the new list
- * of created components, so nothing will happen to them.
- */
- private void removeFormerChildren(UIComponent component)
- {
- Set formerChildIdsSet = (Set)component.getAttributes().get(FORMER_CHILD_IDS_SET_ATTR);
- if (formerChildIdsSet != null)
- {
- for (Iterator iterator = formerChildIdsSet.iterator(); iterator.hasNext();)
- {
- String childId = (String)iterator.next();
- if (_childrenAdded == null || !_childrenAdded.contains(childId))
- {
- UIComponent childToRemove = component.findComponent(childId);
- if (childToRemove != null)
- {
- component.getChildren().remove(childToRemove);
- }
- }
- }
- if (_childrenAdded == null)
- {
- component.getAttributes().remove(FORMER_CHILD_IDS_SET_ATTR);
- }
- else
- {
- component.getAttributes().put(FORMER_CHILD_IDS_SET_ATTR, _childrenAdded);
- }
- }
- else
- {
- if (_childrenAdded != null)
- {
- component.getAttributes().put(FORMER_CHILD_IDS_SET_ATTR, _childrenAdded);
- }
- }
- }
-
- /** See removeFormerChildren. */
- private void removeFormerFacets(UIComponent component)
- {
- Set formerFacetNamesSet = (Set)component.getAttributes().get(FORMER_FACET_NAMES_SET_ATTR);
- if (formerFacetNamesSet != null)
- {
- for (Iterator iterator = formerFacetNamesSet.iterator(); iterator.hasNext();)
- {
- String facetName = (String)iterator.next();
- if (_facetsAdded == null || !_facetsAdded.contains(facetName))
- {
- component.getFacets().remove(facetName);
- }
- }
- if (_facetsAdded == null)
- {
- component.getAttributes().remove(FORMER_FACET_NAMES_SET_ATTR);
- }
- else
- {
- component.getAttributes().put(FORMER_FACET_NAMES_SET_ATTR, _facetsAdded);
- }
- }
- else
- {
- if (_facetsAdded != null)
- {
- component.getAttributes().put(FORMER_FACET_NAMES_SET_ATTR, _facetsAdded);
- }
- }
- }
-
- /**
- * Invoke encodeBegin on the associated UIComponent. Subclasses can
- * override this method to perform custom processing before or after
- * the UIComponent method invocation.
- */
- protected void encodeBegin()
- throws IOException
- {
- if(log.isDebugEnabled())
- log.debug("Entered encodeBegin for client-Id: "+_componentInstance.getClientId(getFacesContext()));
- _componentInstance.encodeBegin(getFacesContext());
- if(log.isDebugEnabled())
- log.debug("Exited encodeBegin");
- }
-
- /**
- * Invoke encodeChildren on the associated UIComponent. Subclasses can
- * override this method to perform custom processing before or after
- * the UIComponent method invocation. This is only invoked for components
- * whose getRendersChildren method returns true.
- */
- protected void encodeChildren()
- throws IOException
- {
- if(log.isDebugEnabled())
- log.debug("Entered encodeChildren for client-Id: "+_componentInstance.getClientId(getFacesContext()));
- _componentInstance.encodeChildren(getFacesContext());
- if(log.isDebugEnabled())
- log.debug("Exited encodeChildren for client-Id: "+_componentInstance.getClientId(getFacesContext()));
- }
-
- /**
- * Invoke encodeEnd on the associated UIComponent. Subclasses can override this
- * method to perform custom processing before or after the UIComponent method
- * invocation.
- */
- protected void encodeEnd()
- throws IOException
- {
- if(log.isDebugEnabled())
- log.debug("Entered encodeEnd for client-Id: "+_componentInstance.getClientId(getFacesContext()));
- _componentInstance.encodeEnd(getFacesContext());
- if(log.isDebugEnabled())
- log.debug("Exited encodeEnd for client-Id: "+_componentInstance.getClientId(getFacesContext()));
-
- }
-
- /**
- * Return the corresponding UIComponent for this tag, creating it
- * if necessary.
- * <p>
- * If this is not the first time this method has been called, then
- * return the cached component instance found last time.
- * <p>
- * If this is not the first time this view has been seen, then
- * locate the existing component using the id attribute assigned
- * to this tag and return it. Note that this is simple for
- * components with user-assigned ids. For components with
- * generated ids, the "reattachment" relies on the fact that
- * UIViewRoot will generate the same id values for tags in
- * this page as it did when first generating the view. For this
- * reason all JSF tags within a JSTL "c:if" are required to have
- * explicitly-assigned ids.
- * <p>
- * Otherwise create the component, populate its properties from
- * the xml attributes on this JSP tag and attach it to its parent.
- * <p>
- * When a component is found or created the parent JSP tag is also
- * told that the component has been "seen". When the parent tag
- * ends it will delete any components which were in the view
- * previously but have not been seen this time; see doEndTag for
- * more details.
- */
- protected UIComponent findComponent(FacesContext context)
- throws JspException
- {
- if (_componentInstance != null) return _componentInstance;
- UIComponentTag parentTag = getParentUIComponentTag(pageContext);
- if (parentTag == null)
- {
- //This is the root
- _componentInstance = context.getViewRoot();
- setProperties(_componentInstance);
- return _componentInstance;
- }
-
- UIComponent parent = parentTag.getComponentInstance();
- //TODO: what if parent == null?
- if (parent == null) throw new IllegalStateException("parent is null?");
-
- String facetName = getFacetName();
- if (facetName != null)
- {
- //Facet
- String id = getOrCreateUniqueId(context);
- _componentInstance = parent.getFacet(facetName);
- if (_componentInstance == null)
- {
- _componentInstance = createComponentInstance(context, id);
- setProperties(_componentInstance);
- parent.getFacets().put(facetName, _componentInstance);
- }
- else
- {
- if (checkFacetNameOnParentExists(parentTag, facetName))
- {
- throw new IllegalStateException("facet '" + facetName + "' already has a child associated. current associated component id: "
- + _componentInstance.getClientId(context) + " class: " + _componentInstance.getClass().getName());
- }
- }
-
- addFacetNameToParentTag(parentTag, facetName);
- return _componentInstance;
- }
- else
- {
- //Child
- //
- // Note that setProperties is called only when we create the
- // component; on later passes, the attributes defined on the
- // JSP tag are set on this Tag object, but then completely
- // ignored.
-
- String id = getOrCreateUniqueId(context);
-
- // Warn users that this tag is about to find/steal the UIComponent
- // that has already been created for a sibling tag with the same id value .
- // _childrenAdded is a Set, and we will stomp over a past id when calling
- // addChildIdToParentTag.
- //
- // It would also be reasonable to throw an exception here rather than
- // just issue a warning as this is a pretty serious problem. However the
- // Sun RI just issues a warning...
- if(parentTag._childrenAdded != null && parentTag._childrenAdded.contains(id))
- {
- if(log.isWarnEnabled())
- log.warn("There is more than one JSF tag with an id : " + id);
- }
-
- _componentInstance = findComponent(parent,id);
- if (_componentInstance == null)
- {
- _componentInstance = createComponentInstance(context, id);
- setProperties(_componentInstance);
- int index = getAddedChildrenCount(parentTag);
- List children = parent.getChildren();
- if (index <= children.size())
- {
- children.add(index, _componentInstance);
- }
- else
- {
- throw new FacesException("cannot add component with id '" +
- _componentInstance.getId() + " to its parent component with id : '"+parent.getId()+"' and path '"+
- getPathToComponent(parent)+"'at position :"+index+" in list of children. "+
- "This might be a problem due to a duplicate id in a previously added component,"+
- "if this is the case, the problematic id might be one of : "+printSet(parentTag._childrenAdded));
- }
- }
- addChildIdToParentTag(parentTag, id);
- return _componentInstance;
- }
- }
-
- private UIComponent findComponent(UIComponent parent, String id)
- {
- List li = parent.getChildren();
-
- for (int i = 0; i < li.size(); i++)
- {
- UIComponent uiComponent = (UIComponent) li.get(i);
- if(uiComponent.getId()!=null && uiComponent.getId().equals(id))
- {
- return uiComponent;
- }
- }
-
- return null;
- }
-
- /**
- * Utility method for creating diagnostic output.
- */
- private String printSet(Set childrenAdded)
- {
- StringBuffer buf = new StringBuffer();
-
- if(childrenAdded!=null)
- {
- Iterator it = childrenAdded.iterator();
-
- while (it.hasNext())
- {
- Object obj = it.next();
- buf.append(obj);
-
- if(it.hasNext())
- buf.append(",");
- }
- }
- return buf.toString();
- }
-
-
- private String getOrCreateUniqueId(FacesContext context)
- {
- String id = getId();
- if (id != null)
- {
- return id;
- }
- else
- {
- //we've been calling
- //return context.getViewRoot().createUniqueId(); - don't want that anymore
- Long currentCounter = (Long) context.getExternalContext().getRequestMap().get(UNIQUE_ID_COUNTER_ATTR);
- long lCurrentCounter = 0;
-
- if(currentCounter!=null)
- {
- lCurrentCounter = currentCounter.longValue();
- }
-
- StringBuffer retValue = new StringBuffer(UIViewRoot.UNIQUE_ID_PREFIX);
- retValue.append("Jsp");
- retValue.append(lCurrentCounter);
-
- lCurrentCounter++;
-
- context.getExternalContext().getRequestMap().put(UNIQUE_ID_COUNTER_ATTR,new Long(lCurrentCounter));
-
- ExternalContext extCtx = FacesContext.getCurrentInstance().getExternalContext();
- return extCtx.encodeNamespace(retValue.toString());
- }
- }
-
- /**
* Create a UIComponent. Abstract method getComponentType is invoked to
* determine the actual type name for the component to be created.
- *
+ *
* If this tag has a "binding" attribute, then that is immediately
* evaluated to store the created component in the specified property.
*/
- private UIComponent createComponentInstance(FacesContext context, String id)
+ protected UIComponent createComponent(FacesContext context, String id)
{
String componentType = getComponentType();
if (componentType == null)
@@ -695,134 +163,22 @@
componentType);
component.setId(id);
component.setValueBinding("binding", componentBinding);
- recurseFacetsAndChildrenForId(component.getFacetsAndChildren(), id + "_", 0);
- _created = true;
+
return component;
}
else
{
UIComponent component = context.getApplication().createComponent(componentType);
component.setId(id);
- _created = true;
- return component;
- }
- }
- /**
- * Recurse all facets and children and assign them an unique ID if
- * necessary. We must *not* use UIViewRoot#createUniqueId here,
- * because this would affect the order of the created ids upon
- * rerendering the page!
- */
- private int recurseFacetsAndChildrenForId(
- Iterator facetsAndChildren,
- String idPrefix,
- int cnt)
- {
- while (facetsAndChildren.hasNext())
- {
- UIComponent comp = (UIComponent)facetsAndChildren.next();
- if (comp.getId() == null)
- {
- ++cnt;
- comp.setId(idPrefix + cnt);
- }
- cnt = recurseFacetsAndChildrenForId(comp.getFacetsAndChildren(), idPrefix, cnt);
- }
- return cnt;
- }
-
- /**
- * Notify the enclosing JSP tag of the id of this component's id. The
- * parent tag will later delete any existing view components that were
- * not seen during this rendering phase; see doEndTag for details.
- */
- private void addChildIdToParentTag(UIComponentTag parentTag, String id)
- {
- if (parentTag._childrenAdded == null)
- {
- parentTag._childrenAdded = new HashSet();
- }
- parentTag._childrenAdded.add(id);
- }
-
- /**
- * check if the facet is already added to the parent
- */
- private boolean checkFacetNameOnParentExists(UIComponentTag parentTag, String facetName)
- {
- return parentTag._facetsAdded != null && parentTag._facetsAdded.contains(facetName);
- }
-
- /**
- * Notify the enclosing JSP tag of the id of this facet's id. The parent
- * tag will later delete any existing view facets that were not seen
- * during this rendering phase; see doEndTag for details.
- */
- private void addFacetNameToParentTag(UIComponentTag parentTag, String facetName)
- {
- if (parentTag._facetsAdded == null)
- {
- parentTag._facetsAdded = new HashSet();
- }
- parentTag._facetsAdded.add(facetName);
- }
-
- private int getAddedChildrenCount(UIComponentTag parentTag)
- {
- return parentTag._childrenAdded != null ?
- parentTag._childrenAdded.size() :
- 0;
- }
-
- /**
- * Get the value to be returned by the doStartTag method to the
- * JSP framework. Subclasses which wish to use the inherited
- * doStartTag but control whether the tag is permitted to contain
- * nested tags or not can just override this method to return
- * Tag.SOME_CONSTANT.
- *
- * @return Tag.EVAL_BODY_INCLUDE
- */
- protected int getDoStartValue()
- throws JspException
- {
- return Tag.EVAL_BODY_INCLUDE;
- }
-
- /**
- * Get the value to be returned by the doEndTag method to the
- * JSP framework. Subclasses which wish to use the inherited
- * doEndTag but control whether the tag is permitted to contain
- * nested tags or not can just override this method to return
- * Tag.SOME_CONSTANT.
- *
- * @return Tag.EVAL_PAGE
- */
- protected int getDoEndValue()
- throws JspException
- {
- return Tag.EVAL_PAGE;
- }
-
- protected FacesContext getFacesContext()
- {
- if (_facesContext == null)
- {
- _facesContext = FacesContext.getCurrentInstance();
+ return component;
}
- return _facesContext;
}
private boolean isFacet()
{
- return _parent != null && _parent instanceof FacetTag;
- }
-
- protected String getFacetName()
- {
- return isFacet() ? ((FacetTag)_parent).getName() : null;
+ return getParent() != null && getParent() instanceof FacetTag;
}
/**
@@ -884,7 +240,7 @@
{
if (getRendererType() != null)
{
- _componentInstance.setRendererType(getRendererType());
+ getComponentInstance().setRendererType(getRendererType());
}
if (_rendered != null)
@@ -901,94 +257,34 @@
}
}
- protected void setupResponseWriter()
+ /**
+ * Class used to create an UIComponentTag from a UIComponentClassicTagBase
+ */
+ private static class UIComponentTagWrapper extends UIComponentTag
{
- FacesContext facesContext = getFacesContext();
-
- if(facesContext == null)
+ public UIComponentTagWrapper(UIComponentClassicTagBase classicTag)
{
- log.error("Faces context not found. getResponseWriter will fail. Check if the FacesServlet has been initialized at all in your web.xml.");
+ setId(classicTag.getId());
+ setJspId(classicTag.getJspId());
+ setParent(classicTag.getParent());
}
- _writer = facesContext.getResponseWriter();
- if (_writer == null)
+ public String getComponentType()
{
- RenderKitFactory renderFactory = (RenderKitFactory)FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
- RenderKit renderKit = renderFactory.getRenderKit(facesContext,
- facesContext.getViewRoot().getRenderKitId());
-
- _writer = renderKit.createResponseWriter(new _PageContextOutWriter(pageContext),
- null /*Default: get the allowed content-types from the accept-header*/,
- pageContext.getRequest().getCharacterEncoding());
- facesContext.setResponseWriter(_writer);
+ return null;
}
- }
-
- /** Generate diagnostic output. */
- private String getPathToComponent(UIComponent component)
- {
- StringBuffer buf = new StringBuffer();
- if(component == null)
+ public String getRendererType()
{
- buf.append("{Component-Path : ");
- buf.append("[null]}");
- return buf.toString();
+ return null;
}
- getPathToComponent(component,buf);
-
- buf.insert(0,"{Component-Path : ");
- buf.append("}");
-
- return buf.toString();
- }
-
- /** Generate diagnostic output. */
- private static void getPathToComponent(UIComponent component, StringBuffer buf)
- {
- if(component == null)
- return;
-
- StringBuffer intBuf = new StringBuffer();
-
- intBuf.append("[Class: ");
- intBuf.append(component.getClass().getName());
- if(component instanceof UIViewRoot)
- {
- intBuf.append(",ViewId: ");
- intBuf.append(((UIViewRoot) component).getViewId());
- }
- else
+ protected UIComponent createComponent(FacesContext context, String newId)
{
- intBuf.append(",Id: ");
- intBuf.append(component.getId());
+ return null;
}
- intBuf.append("]");
- buf.insert(0,intBuf);
- getPathToComponent(component.getParent(),buf);
- }
-
- /**
- * Returns a request scoped stack, creating one if necessary.
- *
- * @see UIComponentClassicTagBase.getStack()
- */
-
- private static final Stack getStack(PageContext pageContext){
-
- Stack stack = (Stack) pageContext.getAttribute(COMPONENT_STACK_ATTR,
- PageContext.REQUEST_SCOPE);
-
- if(stack == null){
- stack = new Stack();
- pageContext.setAttribute(COMPONENT_STACK_ATTR, stack,
- PageContext.REQUEST_SCOPE);
- }
-
- return stack;
}
}
Added: myfaces/shared/branches/3_0_0/core/src/main/java/org/apache/myfaces/shared/taglib/UIComponentELTagBase.java
URL: http://svn.apache.org/viewvc/myfaces/shared/branches/3_0_0/core/src/main/java/org/apache/myfaces/shared/taglib/UIComponentELTagBase.java?view=auto&rev=462531
==============================================================================
--- myfaces/shared/branches/3_0_0/core/src/main/java/org/apache/myfaces/shared/taglib/UIComponentELTagBase.java (added)
+++ myfaces/shared/branches/3_0_0/core/src/main/java/org/apache/myfaces/shared/taglib/UIComponentELTagBase.java Tue Oct 10 12:49:22 2006
@@ -0,0 +1,234 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.myfaces.shared.taglib;
+
+import org.apache.myfaces.shared.renderkit.JSFAttr;
+
+import javax.faces.webapp.UIComponentTag;
+import javax.faces.webapp.UIComponentELTag;
+import javax.faces.component.UIComponent;
+import javax.el.ValueExpression;
+import javax.el.ELContext;
+import javax.el.MethodExpression;
+
+/**
+ * @author Manfred Geiler (latest modification by $Author$)
+ * @author Bruno Aranda (JSR-252)
+ * @version $Revision$ $Date$
+ */
+public abstract class UIComponentELTagBase
+ extends UIComponentELTag
+{
+ //private static final Log log = LogFactory.getLog(UIComponentTagBase.class);
+
+ //UIComponent attributes
+ private ValueExpression _forceId;
+
+ private ValueExpression _forceIdIndex;
+ private static final Boolean DEFAULT_FORCE_ID_INDEX_VALUE = Boolean.TRUE;
+
+ private ValueExpression _javascriptLocation;
+ private ValueExpression _imageLocation;
+ private ValueExpression _styleLocation;
+
+ //Special UIComponent attributes (ValueHolder, ConvertibleValueHolder)
+ private ValueExpression _value;
+ private ValueExpression _converter;
+ //attributes id, rendered and binding are handled by UIComponentTag
+
+ public void release() {
+ super.release();
+
+ _forceId = null;
+ _forceIdIndex = null;
+
+ _value=null;
+ _converter=null;
+
+ _javascriptLocation = null;
+ _imageLocation = null;
+ _styleLocation = null;
+ }
+
+ protected void setProperties(UIComponent component)
+ {
+ super.setProperties(component);
+
+ setBooleanProperty(component, org.apache.myfaces.shared.renderkit.JSFAttr.FORCE_ID_ATTR, _forceId);
+ setBooleanProperty(component, org.apache.myfaces.shared.renderkit.JSFAttr.FORCE_ID_INDEX_ATTR, _forceIdIndex, DEFAULT_FORCE_ID_INDEX_VALUE);
+ if (_javascriptLocation != null) setStringProperty(component, JSFAttr.JAVASCRIPT_LOCATION, _javascriptLocation);
+ if (_imageLocation != null) setStringProperty(component, JSFAttr.IMAGE_LOCATION, _imageLocation);
+ if (_styleLocation != null) setStringProperty(component, JSFAttr.STYLE_LOCATION, _styleLocation);
+
+ //rendererType already handled by UIComponentTag
+
+ setValueProperty(component, _value);
+ setConverterProperty(component, _converter);
+ }
+
+ /**
+ * Sets the forceId attribute of the tag. NOTE: Not every tag that extends this class will
+ * actually make use of this attribute. Check the TLD to see which components actually
+ * implement it.
+ *
+ * @param aForceId The value of the forceId attribute.
+ */
+ public void setForceId(ValueExpression aForceId)
+ {
+ _forceId = aForceId;
+ }
+
+ /**
+ * Sets the forceIdIndex attribute of the tag. NOTE: Not every tag that extends this class will
+ * actually make use of this attribute. Check the TLD to see which components actually implement it.
+ *
+ * @param aForceIdIndex The value of the forceIdIndex attribute.
+ */
+ public void setForceIdIndex(ValueExpression aForceIdIndex)
+ {
+ _forceIdIndex = aForceIdIndex;
+ }
+
+ public void setValue(ValueExpression value)
+ {
+ _value = value;
+ }
+
+ public void setConverter(ValueExpression converter)
+ {
+ _converter = converter;
+ }
+
+
+ /**
+ * Sets the javascript location attribute of the tag. NOTE: Not every tag that extends this class will
+ * actually make use of this attribute. Check the TLD to see which components actually implement it.
+ *
+ * @param aJavascriptLocation The alternate javascript location to use.
+ */
+ public void setJavascriptLocation(ValueExpression aJavascriptLocation)
+ {
+ _javascriptLocation = aJavascriptLocation;
+ }
+
+ /**
+ * Sets the image location attribute of the tag. NOTE: Not every tag that extends this class will
+ * actually make use of this attribute. Check the TLD to see which components actually implement it.
+ *
+ * @param aImageLocation The alternate image location to use.
+ */
+ public void setImageLocation(ValueExpression aImageLocation)
+ {
+ _imageLocation = aImageLocation;
+ }
+
+ /**
+ * Sets the style location attribute of the tag. NOTE: Not every tag that extends this class will
+ * actually make use of this attribute. Check the TLD to see which components actually implement it.
+ *
+ * @param aStyleLocation The alternate style location to use.
+ */
+ public void setStyleLocation(ValueExpression aStyleLocation)
+ {
+ _styleLocation = aStyleLocation;
+ }
+
+ // sub class helpers
+
+ protected void setIntegerProperty(UIComponent component, String propName, ValueExpression value)
+ {
+ UIComponentELTagUtils.setIntegerProperty(component, propName, value);
+ }
+
+ protected void setIntegerProperty(UIComponent component, String propName, ValueExpression value, Integer defaultValue)
+ {
+ UIComponentELTagUtils.setIntegerProperty(component, propName, value, defaultValue);
+ }
+
+ protected void setLongProperty(UIComponent component, String propName, ValueExpression value)
+ {
+ UIComponentELTagUtils.setLongProperty(component, propName, value);
+ }
+
+ protected void setLongProperty(UIComponent component, String propName, ValueExpression value, Long defaultValue)
+ {
+ UIComponentELTagUtils.setLongProperty(component, propName, value, defaultValue);
+ }
+
+ protected void setStringProperty(UIComponent component, String propName, ValueExpression value)
+ {
+ UIComponentELTagUtils.setStringProperty(component, propName, value);
+ }
+
+ protected void setStringProperty(UIComponent component, String propName, ValueExpression value, String defaultValue)
+ {
+ UIComponentELTagUtils.setStringProperty(component, propName, value, defaultValue);
+ }
+
+ protected void setBooleanProperty(UIComponent component, String propName, ValueExpression value)
+ {
+ UIComponentELTagUtils.setBooleanProperty(component, propName, value);
+ }
+
+ protected void setBooleanProperty(UIComponent component, String propName, ValueExpression value, Boolean defaultValue)
+ {
+ UIComponentELTagUtils.setBooleanProperty(component, propName, value, defaultValue);
+ }
+
+ private void setValueProperty(UIComponent component, ValueExpression value)
+ {
+ UIComponentELTagUtils.setValueProperty(getFacesContext(), component, value);
+ }
+
+ private void setConverterProperty(UIComponent component, ValueExpression value)
+ {
+ UIComponentELTagUtils.setConverterProperty(getFacesContext(), component, value);
+ }
+
+ protected void addValidatorProperty(UIComponent component, MethodExpression value)
+ {
+ UIComponentELTagUtils.addValidatorProperty(getFacesContext(), component, value);
+ }
+
+ protected void setActionProperty(UIComponent component, MethodExpression action)
+ {
+ UIComponentELTagUtils.setActionProperty(getFacesContext(), component, action);
+ }
+
+ protected void setActionListenerProperty(UIComponent component, MethodExpression actionListener)
+ {
+ UIComponentELTagUtils.addActionListenerProperty(getFacesContext(), component, actionListener);
+ }
+
+ protected void addValueChangedListenerProperty(UIComponent component, MethodExpression valueChangedListener)
+ {
+ UIComponentELTagUtils.addValueChangedListenerProperty(getFacesContext(), component, valueChangedListener);
+ }
+
+ protected void setValueBinding(UIComponent component,
+ String propName,
+ ValueExpression value)
+ {
+ UIComponentELTagUtils.setValueBinding(getFacesContext(), component, propName, value);
+ }
+
+ protected Object evaluateValueExpression(ValueExpression expression)
+ {
+ return UIComponentELTagUtils.evaluateValueExpression(getFacesContext().getELContext(), expression);
+ }
+
+
+}
Propchange: myfaces/shared/branches/3_0_0/core/src/main/java/org/apache/myfaces/shared/taglib/UIComponentELTagBase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/shared/branches/3_0_0/core/src/main/java/org/apache/myfaces/shared/taglib/UIComponentELTagBase.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Modified: myfaces/shared/branches/3_0_0/core/src/main/java/org/apache/myfaces/shared/taglib/UIComponentELTagUtils.java
URL: http://svn.apache.org/viewvc/myfaces/shared/branches/3_0_0/core/src/main/java/org/apache/myfaces/shared/taglib/UIComponentELTagUtils.java?view=diff&rev=462531&r1=462530&r2=462531
==============================================================================
--- myfaces/shared/branches/3_0_0/core/src/main/java/org/apache/myfaces/shared/taglib/UIComponentELTagUtils.java (original)
+++ myfaces/shared/branches/3_0_0/core/src/main/java/org/apache/myfaces/shared/taglib/UIComponentELTagUtils.java Tue Oct 10 12:49:22 2006
@@ -49,27 +49,43 @@
{
private static final Log log = LogFactory.getLog(UIComponentELTagUtils.class);
- private static final Class[] VALIDATOR_ARGS = {FacesContext.class,
- UIComponent.class,
- Object.class};
- private static final Class[] ACTION_LISTENER_ARGS = {ActionEvent.class};
- private static final Class[] VALUE_LISTENER_ARGS = {ValueChangeEvent.class};
-
private UIComponentELTagUtils() {} //util class, no instantiation allowed
/**
* @since 1.2
*/
- public static void setIntegerProperty(FacesContext context,
- UIComponent component,
+ public static void setIntegerProperty(UIComponent component,
String propName,
ValueExpression value)
{
- String strValue = (String) evaluateValueExpression(context.getELContext(), value);
+ setIntegerProperty(component, propName, value);
+ }
- if (strValue != null)
+ /**
+ * @since 1.2
+ */
+ public static void setIntegerProperty(UIComponent component,
+ String propName,
+ ValueExpression value,
+ Integer defaultValue)
+ {
+ if (value != null)
+ {
+ if (value.isLiteralText())
+ {
+ component.getAttributes().put(propName, Integer.valueOf(value.getExpressionString()));
+ }
+ else
+ {
+ component.setValueExpression(propName, value);
+ }
+ }
+ else
{
- component.getAttributes().put(propName, Integer.valueOf(value.getExpressionString()));
+ if (defaultValue != null)
+ {
+ component.getAttributes().put(propName, defaultValue);
+ }
}
}
@@ -77,48 +93,115 @@
/**
* @since 1.2
*/
- public static void setLongProperty(FacesContext context,
- UIComponent component,
+ public static void setLongProperty(UIComponent component,
String propName,
ValueExpression value)
{
- String strValue = (String) evaluateValueExpression(context.getELContext(), value);
+ setLongProperty(component, propName, value, null);
+ }
- if (strValue != null)
+ /**
+ * @since 1.2
+ */
+ public static void setLongProperty(UIComponent component,
+ String propName,
+ ValueExpression value,
+ Long defaultValue)
+ {
+ if (value != null)
+ {
+ if (value.isLiteralText())
+ {
+ component.getAttributes().put(propName, Long.valueOf(value.getExpressionString()));
+ }
+ else
+ {
+ component.setValueExpression(propName, value);
+ }
+ }
+ else
{
- component.getAttributes().put(propName, Long.valueOf(value.getExpressionString()));
+ if (defaultValue != null)
+ {
+ component.getAttributes().put(propName, defaultValue);
+ }
}
}
/**
* @since 1.2
*/
- public static void setStringProperty(FacesContext context,
- UIComponent component,
+ public static void setStringProperty(UIComponent component,
String propName,
ValueExpression value)
{
- String strValue = (String) evaluateValueExpression(context.getELContext(), value);
+ setStringProperty(component, propName, value, null);
+ }
- if (strValue != null)
+ /**
+ * @since 1.2
+ */
+ public static void setStringProperty(UIComponent component,
+ String propName,
+ ValueExpression value,
+ String defaultValue)
+ {
+ if (value != null)
{
- component.getAttributes().put(propName, value.getExpressionString());
+ if (value.isLiteralText())
+ {
+ component.getAttributes().put(propName, value.getExpressionString());
+ }
+ else
+ {
+ component.setValueExpression(propName, value);
+ }
+ }
+ else
+ {
+ if (defaultValue != null)
+ {
+ component.getAttributes().put(propName, defaultValue);
+ }
}
}
+
/**
* @since 1.2
*/
- public static void setBooleanProperty(FacesContext context,
- UIComponent component,
+ public static void setBooleanProperty(UIComponent component,
String propName,
ValueExpression value)
{
- String strValue = (String) evaluateValueExpression(context.getELContext(), value);
+ setBooleanProperty(component, propName, value);
+ }
- if (strValue != null)
+ /**
+ * @since 1.2
+ */
+ public static void setBooleanProperty(UIComponent component,
+ String propName,
+ ValueExpression value,
+ Boolean defaultValue)
+ {
+ if (value != null)
+ {
+ if (value.isLiteralText())
+ {
+ component.getAttributes().put(propName, Boolean.valueOf(value.getExpressionString()));
+ }
+ else
+ {
+ component.setValueExpression(propName, value);
+ }
+ }
+ else
{
- component.getAttributes().put(propName, Boolean.valueOf(value.getExpressionString()));
+ if (defaultValue != null)
+ {
+ component.getAttributes().put(propName, defaultValue);
+ }
}
}
Modified: myfaces/shared/branches/3_0_0/core/src/main/java/org/apache/myfaces/shared/taglib/UIComponentTagBase.java
URL: http://svn.apache.org/viewvc/myfaces/shared/branches/3_0_0/core/src/main/java/org/apache/myfaces/shared/taglib/UIComponentTagBase.java?view=diff&rev=462531&r1=462530&r2=462531
==============================================================================
--- myfaces/shared/branches/3_0_0/core/src/main/java/org/apache/myfaces/shared/taglib/UIComponentTagBase.java (original)
+++ myfaces/shared/branches/3_0_0/core/src/main/java/org/apache/myfaces/shared/taglib/UIComponentTagBase.java Tue Oct 10 12:49:22 2006
@@ -23,6 +23,8 @@
/**
* @author Manfred Geiler (latest modification by $Author$)
* @version $Revision$ $Date$
+ *
+ * @deprecated use {@link UIComponentELTagBase} instead
*/
public abstract class UIComponentTagBase
extends UIComponentTag
Modified: myfaces/shared/branches/3_0_0/pom.xml
URL: http://svn.apache.org/viewvc/myfaces/shared/branches/3_0_0/pom.xml?view=diff&rev=462531&r1=462530&r2=462531
==============================================================================
--- myfaces/shared/branches/3_0_0/pom.xml (original)
+++ myfaces/shared/branches/3_0_0/pom.xml Tue Oct 10 12:49:22 2006
@@ -41,6 +41,16 @@
</repositories>
<dependencies>
<dependency>
+ <groupId>org.apache.tomcat</groupId>
+ <artifactId>el-api</artifactId>
+ <version>6.0.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tomcat</groupId>
+ <artifactId>jasper-el</artifactId>
+ <version>6.0.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
<groupId>easymock</groupId>
<artifactId>easymockclassextension</artifactId>
<version>1.1</version>
@@ -61,13 +71,13 @@
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
- <version>2.3</version>
+ <version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
- <groupId>javax.servlet</groupId>
+ <groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
- <version>2.0</version>
+ <version>2.1</version>
<scope>provided</scope>
</dependency>
<dependency>