Evaluating methods prior to validation in Spring Webflow
Webflow allows you to execute partic开发者_StackOverflow社区ular 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?
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
...
}
}
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.
精彩评论