dev@javaserverfaces.java.net

Seeking Review [1468-DefalutAttributeValues]

From: Ed Burns <Ed.Burns_at_Sun.COM>
Date: Thu, 31 Dec 2009 13:18:01 -0500

Issue: 1468

SECTION: Modified Files
----------------------------
M common/ant/common.xml

- Because 2.0.2 is out, it is time to mark the currently in development
   version as 2.0.3-SNAPSHOT.

M jsf-ri/src/com/sun/faces/application/ApplicationImpl.java

- In Application.createComponent(Resource), force the population of any
   default composite component attributes into the attributes map. Ryan,
   I found that I needed to explicitly handle the isLiteralText() case
   when I pushed the values into the map. I'm not sure this is the right
   place to handle it, but if it's not done, then my call to
   component.getAttributes("attrName") gives me an instance of
   TagValueExpression, when I really just want what's on the right hand
   side of the "default" attribute on <cc:attribute>.

SECTION: Diffs
----------------------------
Index: common/ant/common.xml
===================================================================
--- common/ant/common.xml (revision 8242)
+++ common/ant/common.xml (working copy)
@@ -95,7 +95,7 @@
      <!-- Version -->
      <property name="spec.version" value="2.0"/>
      <property name="spec.snapshot.version" value="2.1-SNAPSHOT"/>
- <property name="patch.version" value="2"/>
+ <property name="patch.version" value="3"/>
      <property name="impl.name" value="Mojarra"/>
      <property name="build.number" value="${DSTAMP}"/>
      <property name="build.type" value="SNAPSHOT"/>
Index: jsf-ri/src/com/sun/faces/application/ApplicationImpl.java
===================================================================
--- jsf-ri/src/com/sun/faces/application/ApplicationImpl.java (revision
8242)
+++ jsf-ri/src/com/sun/faces/application/ApplicationImpl.java (working copy)
@@ -106,6 +106,7 @@

  import java.beans.BeanDescriptor;
  import java.beans.BeanInfo;
+import java.beans.PropertyDescriptor;
  import java.util.LinkedHashSet;

  import javax.faces.event.ExceptionQueuedEvent;
@@ -1004,15 +1005,36 @@
          assert (null != result);

          result.setRendererType("javax.faces.Composite");
- result.getAttributes().put(Resource.COMPONENT_RESOURCE_KEY,
+ Map<String, Object> attrs = result.getAttributes();
+ attrs.put(Resource.COMPONENT_RESOURCE_KEY,
                  componentResource);
- result.getAttributes().put(UIComponent.BEANINFO_KEY,
+ attrs.put(UIComponent.BEANINFO_KEY,
                  componentMetadata);


associate.getAnnotationManager().applyComponentAnnotations(context, result);
+ pushDeclaredDefaultValuesToAttributesMap(context,
componentMetadata, attrs);

+
          return result;
      }
+
+ private void pushDeclaredDefaultValuesToAttributesMap(FacesContext
context,
+ BeanInfo componentMetadata, Map<String, Object> attrs) {
+ PropertyDescriptor[] declaredAttributes =
componentMetadata.getPropertyDescriptors();
+ Object defaultValue;
+ String key;
+ for (PropertyDescriptor cur : declaredAttributes) {
+ if (null != (defaultValue = cur.getValue("default"))) {
+ key = cur.getName();
+ if (defaultValue instanceof ValueExpression) {
+ if (((ValueExpression)defaultValue).isLiteralText()) {
+ defaultValue =
((ValueExpression)defaultValue).getValue(context.getELContext());
+ }
+ }
+ attrs.put(key, defaultValue);
+ }
+ }
+ }