Saturday, March 27, 2010

Extended errors tag for Stripes

If you ever need to have two or more event methods in a single Stripes ActionBean you can copy the ErrorsTag and add the following lines in the doStartTag method:

                if (getAction().equals(mainAction)) {
                    if (getEvent() != null) {
                        Configuration config = StripesFilter.getConfiguration();
                        ActionResolver resolver = config.getActionResolver();
                        String eventName = resolver.getEventName(mainBean.getClass(), mainBean.getContext());
                        if (getEvent().equals(eventName)) {
                            errors = mainBean.getContext().getValidationErrors();
                    } else {
                        errors = mainBean.getContext().getValidationErrors();

And add get/setEvent methods and add an attribute element to the TLD file and you're set to go.

will ONLY display errors when action is "" AND event is "addObject". I've used this when having two forms on the same page associated with the same ActionBean (to avoid having to write an extra ActionBean bound to another action URI). It might be kinda anti-pattern but my two forms are close related but different data is validated using the @Validate( on="addObject" ) annotation etc.  

oohhh luv that Stripes :-) 


Post a Comment

<< Home