You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by or...@apache.org on 2005/09/09 18:22:12 UTC
svn commit: r279807 -
/myfaces/impl/trunk/src/java/org/apache/myfaces/config/ManagedBeanBuilder.java
Author: oros
Date: Fri Sep 9 09:22:06 2005
New Revision: 279807
URL: http://svn.apache.org/viewcvs?rev=279807&view=rev
Log:
MYFACES-535
MYFACES-536
fixed map/list property initialization to follow the spec
Modified:
myfaces/impl/trunk/src/java/org/apache/myfaces/config/ManagedBeanBuilder.java
Modified: myfaces/impl/trunk/src/java/org/apache/myfaces/config/ManagedBeanBuilder.java
URL: http://svn.apache.org/viewcvs/myfaces/impl/trunk/src/java/org/apache/myfaces/config/ManagedBeanBuilder.java?rev=279807&r1=279806&r2=279807&view=diff
==============================================================================
--- myfaces/impl/trunk/src/java/org/apache/myfaces/config/ManagedBeanBuilder.java (original)
+++ myfaces/impl/trunk/src/java/org/apache/myfaces/config/ManagedBeanBuilder.java Fri Sep 9 09:22:06 2005
@@ -27,6 +27,7 @@
import javax.faces.el.ValueBinding;
import javax.faces.webapp.UIComponentTag;
import java.util.*;
+import java.lang.reflect.Array;
/**
@@ -95,6 +96,9 @@
private void initializeProperties(FacesContext facesContext, Iterator managedProperties, Object bean)
{
+ PropertyResolver propertyResolver =
+ facesContext.getApplication().getPropertyResolver();
+
while (managedProperties.hasNext())
{
ManagedProperty property = (ManagedProperty) managedProperties.next();
@@ -103,54 +107,36 @@
switch (property.getType())
{
case ManagedProperty.TYPE_LIST:
- if (property.getPropertyClass() != null)
- {
- Class listClass = ClassUtils.simpleJavaTypeToClass(property.getPropertyClass());
- try
- {
- value = listClass.newInstance();
-
- if(!(value instanceof List))
- {
- log.error("Supplied type is no instance of java.util.List");
- value = new ArrayList();
- }
+ value = propertyResolver.getValue(bean, property.getPropertyName());
+
+ if (value instanceof List) {
+ initializeList(facesContext, property.getListEntries(), (List) value);
+
+ } else if (value != null && value.getClass().isArray()) {
+ int length = Array.getLength(value);
+ ArrayList temp = new ArrayList(length);
+ for (int i = 0; i < length; i++) {
+ temp.add(Array.get(value, i));
}
- catch(Exception ex)
- {
- log.error("Exception while initiating list-type. ",ex);
- value = new ArrayList();
+ initializeList(facesContext, property.getListEntries(), temp);
+ value = Array.newInstance(value.getClass().getComponentType(), temp.size());
+ length = temp.size();
+
+ for (int i = 0; i < length; i++) {
+ Array.set(value, i, temp.get(i));
}
- }
- else
- {
+ } else {
value = new ArrayList();
+ initializeList(facesContext, property.getListEntries(), (List) value);
}
- initializeList(facesContext, property.getListEntries(), (List) value);
+
break;
case ManagedProperty.TYPE_MAP:
- if (property.getPropertyClass() != null)
- {
- Class mapClass = ClassUtils.simpleJavaTypeToClass(property.getPropertyClass());
- try
- {
- value = mapClass.newInstance();
-
- if(!(value instanceof Map))
- {
- log.error("Supplied type is no instance of java.util.Map");
- value = new HashMap();
- }
- }
- catch(Exception ex)
- {
- log.error("Exception while initiating map-type. ",ex);
- value = new HashMap();
- }
- }
- else
- {
- value = new HashMap();
+
+ value = propertyResolver.getValue(bean, property.getPropertyName());
+
+ if (! (value instanceof Map)) {
+ value = new HashMap();
}
initializeMap(facesContext, property.getMapEntries(), (Map) value);
@@ -162,8 +148,6 @@
value = property.getRuntimeValue(facesContext);
break;
}
- PropertyResolver propertyResolver =
- facesContext.getApplication().getPropertyResolver();
Class propertyClass = null;
if (property.getPropertyClass() == null)