[jboss-cvs] jboss-seam/src/ui/org/jboss/seam/ui ...
Peter Muir
peter at bleepbleep.org.uk
Sat Feb 10 18:45:30 EST 2007
User: pmuir
Date: 07/02/10 18:45:30
Modified: src/ui/org/jboss/seam/ui ConverterChain.java
NoSelectionConverter.java
Log:
JBSEAM-814
Revision Changes Path
1.3 +18 -27 jboss-seam/src/ui/org/jboss/seam/ui/ConverterChain.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: ConverterChain.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/ui/org/jboss/seam/ui/ConverterChain.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- ConverterChain.java 7 Feb 2007 14:51:18 -0000 1.2
+++ ConverterChain.java 10 Feb 2007 23:45:30 -0000 1.3
@@ -1,5 +1,7 @@
package org.jboss.seam.ui;
+
+
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -16,21 +18,20 @@
/**
* This class provides a chainable converter for JSF.
*
- * This has been done to support noSelections on s:selectItems.
- *
- * Converters that are not first/last (the converter specfied on the component)
- * need careful implementation
+ * Any JSF converter can be placed at the end of the chain. A converter that is
+ * placed higher up the chain should return ConverterChain.CONTINUE if
+ * conversion has failed. If the all converters run return
+ * ConverterChain.CONTINUE an unconverted value will be returned.
*
* A converter can be placed in the chain with a priority, the order in which
* converters with the same priority is run is not specified.
*
- * The chain will be processed in ascending order for getAsString, descending order
- * for getAsObject
- *
*/
public class ConverterChain implements Converter, StateHolder
{
+ public static final String CONTINUE = "org.jboss.seam.ui.ConverterChain.continue";
+
/**
* This places the converter at the end of the chain. No garuntee is made
* about the order converters which are placed on the queue with this
@@ -80,45 +81,35 @@
public Object getAsObject(FacesContext context, UIComponent component, String value)
throws ConverterException
{
- Object result = null;
+ Object output = null;
Collections.sort(converters);
- Collections.reverse(converters);
for (Converter converter : converters)
{
- result = converter.getAsObject(context, component, value);
- // We can only process more converters if we still have a string
- if (!(result instanceof String))
+ Object result = converter.getAsObject(context, component, value);
+ if (!CONTINUE.equals(result))
{
+ output = result;
break;
}
- else
- {
- value = result.toString();
}
- }
- return result;
+ return output;
}
public String getAsString(FacesContext context, UIComponent component, Object value)
throws ConverterException
{
+ String output = null;
Collections.sort(converters);
for (Converter converter : converters)
{
- value = converter.getAsString(context, component, value);
- if (value instanceof String)
+ String result = converter.getAsString(context, component, value);
+ if (!CONTINUE.equals(result))
{
+ output = result;
break;
}
}
- if (value == null)
- {
- return null;
- }
- else
- {
- return value.toString();
- }
+ return output;
}
/**
1.2 +2 -2 jboss-seam/src/ui/org/jboss/seam/ui/NoSelectionConverter.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: NoSelectionConverter.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/ui/org/jboss/seam/ui/NoSelectionConverter.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- NoSelectionConverter.java 5 Feb 2007 22:54:30 -0000 1.1
+++ NoSelectionConverter.java 10 Feb 2007 23:45:30 -0000 1.2
@@ -16,7 +16,7 @@
} else if (value.equals(NO_SELECTION_VALUE)) {
return null;
} else {
- return value;
+ return ConverterChain.CONTINUE;
}
}
@@ -25,7 +25,7 @@
if (value == null) {
return NO_SELECTION_VALUE;
} else {
- return value.toString();
+ return ConverterChain.CONTINUE;
}
}
More information about the jboss-cvs-commits
mailing list