Hi Chris,

I think the reason is, generally, if you submit a form with values and
there are validation errors, those values are blocked from being bound
on the action bean (validation is about disallowing invalid values,
after all). When redisplaying the form and telling the user about the
errors, we want to repopulate the form with the submitted values, but
those are only available in the request, not from the action bean.

Perhaps you could run your list compression only after validation has
passed (in the event handler)? In the case of errors, the form would be
re-rendered with the values (and error messages) in the same place as
the user entered them, but when all URLs are valid, you could then
clean up the empty slots before saving.

Hope that helps.

Cheers,
Freddy

On Fri, Aug 2, 2013, at 10:48 AM, Chris Cheshire wrote:

I have a form that allows users to enter a series of urls, backed by a
list of strings in the action bean. As a prevalidation method I am
removing empty elements :
    @Before(stages={LifecycleStage.CustomValidation})
    public void removeEmptyImages() {
        this.log.trace("in removeEmptyImages()");
        if (this.images != null) {
            // remove any non existant entries
            ListIterator<String> iter = this.images.listIterator();
            while (iter.hasNext()) {
                String img = iter.next();
                if (img == null) {
                    iter.remove();
                }
            }
        }
    }

So if something was entered in element 0, 1 and 3, the list is
compressed down.

In a @ValidationMethod, the list has validity checks (making sure the
urls are actually valid etc) performed on it and I don't have to deal
with null values. However when one of those items has an error and the
form is rendered again, the validation errors are in the right place
(given that the list has been compressed), but the form values are not.
They are rendered (or attempting to be) where they originally were,
despite using the BFPS. So once elements are removed I get errors
rendered by the wrong inputs.
I took a dig into the code thinking there is a bug, and I find in BFPS
    @Override
    public Object getValue(InputTagSupport tag) throws
StripesJspException {
        // If the specific tag is in error, grab the values from the
request
        if (tag.hasErrors()) {
            return super.getValue(tag);
        }
        else {
            // Try getting from the ActionBean.  If the bean is present
and the property
            // is defined, then the value from the bean takes
precedence even if it's null

My question is why is it reverting to request values if the tag has
errors? My first reaction to a solution is to write my own subclass,
copying the code sans the first if block. However, there is probably a
good reason for the BFPS being coded like this, so maybe my solution
will bugger something else.
What am I missing here?

Thanks
Chris

-----------------------------------------------------------------------
-------

Get your SQL database under version control now!

Version control is standard for application code, but databases havent

caught up. So what steps can you take to put your SQL databases under

version control? Why should you start doing it? Read more to find out.

[1]http://pubads.g.doubleclick.net/gampad/clk?id=49501711&iu=/4140/ostg
.clktrk

_______________________________________________

Stripes-users mailing list

[2]Stripes-users@lists.sourceforge.net

[3]https://lists.sourceforge.net/lists/listinfo/stripes-users

References

1. http://pubads.g.doubleclick.net/gampad/clk?id=49501711&iu=/4140/ostg.clktrk
2. mailto:Stripes-users@lists.sourceforge.net
3. https://lists.sourceforge.net/lists/listinfo/stripes-users
------------------------------------------------------------------------------
Get your SQL database under version control now!
Version control is standard for application code, but databases havent 
caught up. So what steps can you take to put your SQL databases under 
version control? Why should you start doing it? Read more to find out.
http://pubads.g.doubleclick.net/gampad/clk?id=49501711&iu=/4140/ostg.clktrk
_______________________________________________
Stripes-users mailing list
Stripes-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/stripes-users

Reply via email to