Hi,

One of the requirements of the app I'm currently working on is to enter comma 
delimited codes into a text area.  I found the useful OneToManyTypeConverter, 
which transparently allows my bean to use a Set<String>, while the user enters 
a delimited string.

@Validate(converter=OneToManyTypeConverter.class)
Set<String> codes;

<stripes:textarea name="codes">1234, 2346, 2345</stripes:textarea>

That's pretty decent, but when the user goes to edit to set I just saved for 
them, the population strategy doesn't provide a delimited string into the text 
area.  I initially figured it was due to the formatter factory not having an 
inverse formatter, so I wrote my own OneToManyFormatter that loops over the 
collection and builds a string.  I subclassed formatter factory, added this 
thing in there, but it never gets called.  What's odd is the first item in the 
set does show up in the text area as a string.

So I went digging through the code, and I found

InputTextAreaTag:
  @Override
    public int doEndInputTag() throws JspException {
        try {
            // Find out if we have a value from the PopulationStrategy
            Object value = getSingleOverrideValue();

InputTagSupport:
  protected Object getSingleOverrideValue() throws StripesJspException {
        Object unknown = getOverrideValueOrValues();
        Object returnValue = null;

        if (unknown != null && unknown.getClass().isArray()) {
            if (Array.getLength(unknown) > 0) {
                returnValue = Array.get(unknown, 0);
            }
        }
        else if (unknown != null && unknown instanceof Collection) {
            Collection<?> collection = (Collection<?>) unknown;
            if (collection.size() > 0) {
                returnValue = collection.iterator().next();
            }
        }
        else {
            returnValue = unknown;
        }

        return returnValue;
    }

So if a text area is trying to populate with a collection, all I can 
potentially format is collection.iterator().next();  the formatter factory 
never gets asked for the set formatter.  The javadoc states:

"This can be used to ensure that
     * only a single value is returned by the population strategy, which is 
useful in the case
     * of text inputs etc. which can have only a single value."

Right, but it doesn't allow the possibility of multiple values being later 
formatted into a single one.  I don't think this is ideal behavior.  Thoughts?

Thanks,
John
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Stripes-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-users

Reply via email to