Author: craigmcc
Date: Tue Jan 17 16:56:48 2006
New Revision: 369991

URL: http://svn.apache.org/viewcvs?rev=369991&view=rev
Log:
Clean up some logic errors surfaced by writing some unit tests using
these two helper classes.

Modified:
    
struts/shale/trunk/core-library/src/java/org/apache/shale/resources/Bundle.properties
    
struts/shale/trunk/core-library/src/java/org/apache/shale/util/ConverterHelper.java
    
struts/shale/trunk/core-library/src/java/org/apache/shale/util/PropertyHelper.java

Modified: 
struts/shale/trunk/core-library/src/java/org/apache/shale/resources/Bundle.properties
URL: 
http://svn.apache.org/viewcvs/struts/shale/trunk/core-library/src/java/org/apache/shale/resources/Bundle.properties?rev=369991&r1=369990&r2=369991&view=diff
==============================================================================
--- 
struts/shale/trunk/core-library/src/java/org/apache/shale/resources/Bundle.properties
 (original)
+++ 
struts/shale/trunk/core-library/src/java/org/apache/shale/resources/Bundle.properties
 Tue Jan 17 16:56:48 2006
@@ -61,5 +61,6 @@
 tiles.dispatchingToViewHandler=Dispatching {0} to the default view handler
 
 # org.apache.shale.util.ConverterHelper
+convHelper.missing=You have requested a converter, but the type specified is 
null
 convHelper.noConverter=You have requested a conversion for type {0}, but there 
is no by-type converter registered for this type
 

Modified: 
struts/shale/trunk/core-library/src/java/org/apache/shale/util/ConverterHelper.java
URL: 
http://svn.apache.org/viewcvs/struts/shale/trunk/core-library/src/java/org/apache/shale/util/ConverterHelper.java?rev=369991&r1=369990&r2=369991&view=diff
==============================================================================
--- 
struts/shale/trunk/core-library/src/java/org/apache/shale/util/ConverterHelper.java
 (original)
+++ 
struts/shale/trunk/core-library/src/java/org/apache/shale/util/ConverterHelper.java
 Tue Jan 17 16:56:48 2006
@@ -61,6 +61,9 @@
      */
     public Object asObject(FacesContext context, Class type, String value) {
 
+        if (String.class == type) {
+            return value;
+        }
         return converter(context, type).getAsObject(context, 
context.getViewRoot(), value);
 
     }
@@ -79,6 +82,11 @@
      */
     public String asString(FacesContext context, Class type, Object value) {
 
+        if (value == null) {
+            return null;
+        } else if ((String.class == type) && (value instanceof String)) {
+            return (String) value;
+        }
         return converter(context, type).getAsString(context, 
context.getViewRoot(), value);
 
     }
@@ -98,6 +106,11 @@
      *  registered for the specified type
      */
     private Converter converter(FacesContext context, Class type) {
+
+        if (type == null) {
+            throw new 
ConverterException(messages.getMessage("convHelper.missing",
+                                                             
context.getViewRoot().getLocale()));
+        }
 
         Converter converter = null;
         try {

Modified: 
struts/shale/trunk/core-library/src/java/org/apache/shale/util/PropertyHelper.java
URL: 
http://svn.apache.org/viewcvs/struts/shale/trunk/core-library/src/java/org/apache/shale/util/PropertyHelper.java?rev=369991&r1=369990&r2=369991&view=diff
==============================================================================
--- 
struts/shale/trunk/core-library/src/java/org/apache/shale/util/PropertyHelper.java
 (original)
+++ 
struts/shale/trunk/core-library/src/java/org/apache/shale/util/PropertyHelper.java
 Tue Jan 17 16:56:48 2006
@@ -165,7 +165,7 @@
 
         BeanInfo beanInfo = null;
         try {
-            Introspector.getBeanInfo(bean.getClass());
+            beanInfo = Introspector.getBeanInfo(bean.getClass());
         } catch (IntrospectionException e) {
             throw new EvaluationException(e);
         }
@@ -178,7 +178,6 @@
             if (name.equals(descriptors[i].getName())) {
                 return descriptors[i];
             }
-            return descriptors[i];
         }
 
         throw new PropertyNotFoundException(name);



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to