Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Evaluating methods prior to validation in Spring Webflow

Webflow allows you to execute particular expressions via the <on-entry> element in a flow.

However is it possible to somehow evaluate an expression BEFORE webflow attempts to validate the page?

like image 984
beatupunit Avatar asked Nov 09 '10 17:11

beatupunit


2 Answers

One trick you could use is to add the necessary logic to the beginning of your validation method, something like this (sample from the reference guide):

<view-state id="enterBookingDetails" model="booking">
    <transition on="proceed" to="reviewBooking">
</view-state>

public class Booking {
    private Date checkinDate;
    private Date checkoutDate;
    ...

    public void validateEnterBookingDetails(ValidationContext context) {
        // do whatever you want to do before attemting validation
        ...

        // now do validation
        ...
    }
}
like image 93
klr8 Avatar answered Sep 22 '22 01:09

klr8


The problem with klr8's answer is that you do not have any information besides the validationContext passed into the validator. If you need other information from your flow, you could try to trigger the validation manually:

<transition on="submit" to="isValid" validate="false">
    <evaluate expression="someLogicIWantToDo(a,b,c)" />
    <evaluate expression="booking.validate(bookingForm, messageContext)"/>
</transition>

<decision-state id="isValid">
    <if test="messageContext.hasErrorMessages()" then="home" else="page2"/>
</decision-state>

Web-flow validate methods can take either a MessageContext or ValidationContext. I am not sure how to access validationContext from Web Flow to manually trigger if you validation methods take validationContext.

like image 20
stephen.hanson Avatar answered Sep 22 '22 01:09

stephen.hanson