Johnathan Smith
Johnathan Smith

Reputation: 1112

Field Validate in Spring Web Flow

Field Validate in Spring Web Flow

I am trying to do my field validate inside the controller of my Spring Web Flow. I have the following code inside my code and it works great if I have a error but if I dont have a error what do I return? Am I doing this the right why?

Code in my controller:

public Event validateVisit(Visit visit, MessageContext messageContext)
{
        String temp = visit.getType_of_visit() + "";
        if(temp.equals(""))
        {   
            MessageBuilder errorMessageBuilder = new MessageBuilder().error();
            errorMessageBuilder.source("type_of_visit");
            errorMessageBuilder.code("type_of_visit_missing");      
            messageContext.addMessage(errorMessageBuilder.build());
            return new EventFactorySupport().error(this);
        }
}

Here is my flow.xml

<view-state id="SchoolVisitReport" view="SchoolVisitReport.jsp" model="visit">
            <transition on="submit" to="addVisit">
                <evaluate expression="flowActions.validateVisit(visit, messageContext)"/>
            </transition>
            <transition on="cancel" to="endState"/>
    </view-state>

<decision-state id="addVisit">
       <if test="flowActions.addVisit(visit)" then="endState" else="errorState" />
 </decision-state>

Please let me know if I am doing this the right what.. I cant get it working if I dont have a error.

Upvotes: 0

Views: 1945

Answers (1)

MetroidFan2002
MetroidFan2002

Reputation: 29878

I believe you use return new EventFactorySupport().success(this); to represent that no error occurred.

Upvotes: 2

Related Questions