0
votes

Spring webflow does not use the custom validator PatientValidator to validate Patient model while transitioning from selectPatient state to selectDoctor state.

Here is my code

Patient.java

@Data
@Entity
public class Patient implements Serializable {
    private static final long serialVersionUID = -5116169782847291743L;

  ...
}

PatientValidator.java

@Component
public class PatientValidator extends FieldValidator {
    public PatientValidator() { }

    public void validateSelectPatient(Patient patient, Errors errors) {
        System.out.println("PatientValidator . validateSelectPatient");
    }

    public void validateSelectDoctor(Patient patient, Errors errors) {
        System.out.println("PatientValidator . validateSelectDoctor");
    }
}

submit-request-flow.xml

<?xml version="1.0" encoding="UTF-8"?>
<flow xmlns="http://www.springframework.org/schema/webflow"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.springframework.org/schema/webflow
                          http://www.springframework.org/schema/webflow/spring-webflow-2.0.xsd">

  <secured attributes="ROLE_OFFICER" match="any"/>

  <on-start>
    <evaluate expression="submitRequestFlow.getPatient()" result="flowScope.patient"></evaluate>
  </on-start>


  <view-state id="selectPatient"  view="flows/requests/new/select-patient" model="patient">
    <transition on="select" to="selectDoctor"></transition>
  </view-state>


  <view-state id="selectDoctor" view="flows/requests/new/select-doctor">
    <transition on="select" to="selectTestType"></transition>
    <transition on="back" to="selectPatient"></transition>
  </view-state>


  ...


  <end-state id="finishFlow" view="externalRedirect:#{uri.get('requests')}">
    <output name="success" value="'Request has been added successfully'"/>
  </end-state>

  <end-state id="cancelFlow" view="externalRedirect:#{uri.get('requests')}">
  </end-state>

  <global-transitions>
    <transition on="cancel" to="cancelFlow" history="discard" bind="false" validate="false"></transition>
  </global-transitions>

</flow>

Even if I use the validation method inside Patient.java, the webflow uses it.

@Data
@Entity
public class Patient implements Serializable {
    private static final long serialVersionUID = -5116169782847291743L;

  ...

  public void validateSelectPatient(Errors errors) {
        errors.reject("NoResultFound");
    }
}

I have to use the custom validation rather than the model one, it works just the first time, but I guess after I rebooted spring boot project it doesn't work anymore.


Update #1

I am using

  • Spring boot 1.5.6.RELEASE
  • Spring WebFlow 2.4.5.RELEASE
  • Thymeleaf 3.0.7.RELEASE
  • Thymeleaf SpringSecurity4 3.0.2.RELEASE
1

1 Answers

0
votes

I guess issue is related how spring DevTools works, here is a workaround I have done for another issue here SpelEvaluationException Method cannot be found.