如何在转换时清除表单(操作)Spring Webflow

how to clear the form on transition (action) Spring Webflow

I am struggling to add a feature to my Spring Webflow app in which one of the stages has a form and a table. The form is bound to a model and on one transition (action) I save the model to the list of scopeModel. The thing is that I dont know how to achieve this using a proper technique.

    <?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">


    <!--ASSIGNING MODELS-->
    <var name="personalInfo" class="com.example.demo.alloystry.models.ApplicantPersonalInfoMain" />
    <var name="employment" class="com.example.demo.alloystry.models.ApplicantEmployment" />
    <var name="experience" class="com.example.demo.alloystry.models.ApplicantExperienceInfo" />
    <var name="experienceList" class="com.example.demo.alloystry.models.ApplicantExperienceList" />
    <var name="education" class="com.example.demo.alloystry.models.step4.Education" />
    <var name="additional" class="com.example.demo.alloystry.models.additionalinfo.ApplicantAdditionalInfo" />



    <!-- returning and adding inside flow registerModel instance -->
    <on-start>
        <evaluate expression="applicantHandler.init()"
                  result="flowScope.registerModel" />
    </on-start>


    <view-state id="personal" view="flows/register/personal-info" model="personalInfo">
        <transition on="employment" to="validatePersonal" />
        <on-exit>
            <evaluate expression="applicantHandler.addPersonalInfo(flowScope.registerModel, personalInfo)"></evaluate>
        </on-exit>
    </view-state>


    <action-state id="validatePersonal">
        <evaluate expression="applicantHandler.validatePersonalInfo(personalInfo, messageContext)" />
        <transition on="success" to="employment" />
        <transition on="failure" to="personal" />
    </action-state>



    <view-state id="employment" view="flows/register/employment" model="employment">
        <transition on="personal" to="personal" />
        <transition on="experience" to="experience" />
        <on-exit>
            <evaluate expression="applicantHandler.addEmploymentInfo(flowScope.registerModel, employment)"></evaluate>
        </on-exit>
    </view-state>



    <!--<view-state id="experience" view="flows/register/experience" model="experience">-->
        <!--<transition on="employment" to="employment" />-->
        <!--<transition on="education" to="education" />-->
        <!--<on-exit>-->
            <!--<evaluate expression="applicantHandler.addExperienceInfo(flowScope.registerModel, experience)"></evaluate>-->
        <!--</on-exit>-->
    <!--</view-state>-->

    <view-state id="experience" view="flows/register/experience" model="experience">

        <on-entry>
            <set name="experience.workPeriod" value="''"/>
            <set name="experience.nameOfOrg" value="''"/>
            <set name="experience.titleOfyourPost" value="''"/>
        </on-entry>

        <transition on="addExperience">
            <evaluate expression="applicantHandler.addExperienceInfo(flowScope.registerModel, experience)" />
        </transition>
        <transition on="employment" to="employment" />
        <transition on="education" to="education" />
        <!--<on-exit>-->
            <!--<evaluate expression="applicantHandler.setExperienceList(flowScope.registerModel.experienceInfoList, experienceList)"></evaluate>-->
        <!--</on-exit>-->
    </view-state>


    <view-state id="education" view="flows/register/education" model="education">
        <transition on="experience" to="experience" />
        <transition on="additional" to="additional" />
        <on-exit>
            <evaluate expression="applicantHandler.addEducationInfo(flowScope.registerModel, education)"></evaluate>
        </on-exit>
    </view-state>



    <view-state id="additional" view="flows/register/education" model="additional">
        <transition on="education" to="education" />
        <transition on="confirm" to="confirm" />
        <on-exit>
            <evaluate expression="applicantHandler.addAdditionalInfo(flowScope.registerModel, additional)"></evaluate>
        </on-exit>
    </view-state>

    <view-state id="confirm" view="flows/register/applicant-confirm" model="flowScope.registerModel">
        <transition on="submit" to="submit" />
    </view-state>



    <action-state id="submit">
        <evaluate expression="registerHandler.saveAll(flowScope.registerModel, messageContext)" />
        <transition on="success" to="success" />
        <transition on="failure" to="confirm" />
    </action-state>



    <!-- end state -->
    <end-state id="success" view="flows/register/signup-success" />
    <!--<end-state id="home" view="externalRedirect:contextRelative:/" />-->

    <!--&lt;!&ndash; Global Transition &ndash;&gt;-->
    <!--<global-transitions>-->
        <!--<transition on="home" to="home" validate="false" />-->
    <!--</global-transitions>-->






</flow>

Model package com.example.demo.alloystry.models;

import com.example.demo.alloystry.models.additionalinfo.ApplicantAdditionalInfo;
import com.example.demo.alloystry.models.step4.Education;
import lombok.Data;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

@Data
public class RegisterModel implements Serializable {

    private static final long serialVersionUID = 1L;

    private ApplicantPersonalInfoMain personalInfo;

    private ApplicantEmployment employment;

//    private ApplicantExperienceInfo experience;


    private List<ApplicantExperienceInfo> experienceInfoList = new ArrayList<ApplicantExperienceInfo>();

    private Education education;

    private ApplicantAdditionalInfo additional; //TODO should be configured

}

Handler

  package com.example.demo.alloystry.handlers;


import com.example.demo.alloystry.models.*;
import com.example.demo.alloystry.models.additionalinfo.ApplicantAdditionalInfo;
import com.example.demo.alloystry.models.step4.Education;
import org.springframework.binding.message.MessageBuilder;
import org.springframework.binding.message.MessageContext;
import org.springframework.stereotype.Component;

@SuppressWarnings("ALL")
@Component
public class ApplicantHandler {

    public RegisterModel init() {
        return new RegisterModel();
    }


    public ApplicantExperienceInfo giveNewExperience() {
        return new ApplicantExperienceInfo();
    }

    public void addPersonalInfo(RegisterModel registerModel, ApplicantPersonalInfoMain personalInfo) {
        registerModel.setPersonalInfo(personalInfo);
    }

    public void addEmploymentInfo(RegisterModel registerModel, ApplicantEmployment employment) {
        registerModel.setEmployment(employment);
    }

//    public void setExperienceList(RegisterModel registerModel, ApplicantExperienceList experiences) {
//        registerModel.setExperiences(experiences);
//    }


    public void addExperienceInfo(RegisterModel registerModel, ApplicantExperienceInfo exp) {
        registerModel.getExperienceInfoList().add(exp);
    }



    public void addEducationInfo(RegisterModel registerModel, Education education){
        registerModel.setEducation(education);
    }


    public void addAdditionalInfo(RegisterModel registerModel, ApplicantAdditionalInfo additional){
        registerModel.setAdditional(additional);
    }


    public String saveAll(RegisterModel registerModel, MessageContext error) {
        String transitionValue = "success";

        // XXX Save model in database or somewhere else...
        error.addMessage(new MessageBuilder(). //
                error() //
                .source("registration") //
                .defaultText( //
                        String.format("Couldn't register user with username: %s!",
                                registerModel.getPersonalInfo().getFirstName())) //
                .build());
        transitionValue = "failure";

        return transitionValue;
    }

    public String validatePersonalInfo(ApplicantPersonalInfoMain personalInfo, MessageContext error) {
        String transitionValue = "success";

        // Checking that username is not equal to 'Vakho' :d XXX do whatever you want!
        if (personalInfo.getFirstName().equalsIgnoreCase("Vakho")) {
            error.addMessage(new MessageBuilder(). //
                    error() //
                    .source("username") //
                    .defaultText("You are not allowed to use Vakho as the username!") //
                    .build());

            transitionValue = "failure";
        }

//        // Checking if password matched the confirm password
//        if (!personalInfo.getPassword().equals(personalInfo.getConfirmPassword())) {
//            error.addMessage(new MessageBuilder(). //
//                    error() //
//                    .source("confirmPassword") //
//                    .defaultText("Password doesn't match up the confirm password!") //
//                    .build());
//
//            transitionValue = "failure";
//        }
        return transitionValue;
    }
}

每当我提交表单时,模型都会保存到列表中,这里没有问题。但是保存后表格没有被刷新。保存的数据显示在现场。我尝试了多种方法来重置表格,但没有成功。问题如下:我需要将多个模型保存到列表中并显示在此特定页面上的 table 上。问题 我怎样才能以正确和简单的方式实现这一目标!提前致谢

您可以在 ApplicationHandler 中添加一个方法,该方法 returns 一个新的 ApplicantPersonalInfoMain "createNewPersonalInfo"

然后使用:

<set name="personalInfo" value="applicantHandler.createNewPersonalInfo()" />

为了重新创建您的模型对象并且应该重置表单