Grails中的Web流程 - 混淆

时间:2015-09-03 14:28:47

标签: grails web spring-webflow flow

每次触摸网络流时,我都只有痛苦,我认为在Spring MVC中,事情可能会更加简单和无法理解,但似乎并非如此。

我有一个简单的情况,我希望在Web流的第一页显示时,在流量范围内已经预填充的命令对象启动Web流。命令对象基本上将从域对象

中保存值的副本

继承我的命令对象:

@grails.validation.Validateable(nullable=false)
class PatientEditFlowCommand implements Serializable{

StepOneCommand stepOneCommand

PatientEditFlowCommand(Patient patient){

    stepOneCommand = new StepOneCommand(
            patientName : "${patient.appUser?.firstName} ${patient.appUser?.lastName}",
            patientDoctorId : patient.doctor?.id,
            patientNurseId : patient.nurse?.id,
            patientStartDate : patient.startDate,
            patientEndDate : patient.endDate,
            patientDrugRegimeId: patient.regime?.id
    )

}

static constraints = {


}
}


@grails.validation.Validateable(nullable=false)
class StepOneCommand implements Serializable{

String patientName //wont be editable

Long patientDoctorId  //user id of assigned doctor
Long patientNurseId   //user id of assigned doctor

Date patientStartDate
Date patientEndDate

Long patientDrugRegimeId

static constraints = {
    patientDoctorId(nullable: false)
    patientNurseId(nullable: false)
    patientStartDate(nullable: false)
    patientEndDate(nullable: false)
    patientDrugRegimeId(nullable: false)
}
}


@grails.validation.Validateable(nullable=false)
class StepTwoCommand implements Serializable{

static constraints = {

}
}

继续我控制器内部的流动:

    def newEditFlow = {

    init {
        //start the flow by transferring domain obj into a command object
        action {
            Patient patient = Patient.get(params.id)
            [patientEditFlowCommand:new PatientEditFlowCommand(patient)]
            success()
        }
        on ("success"){

        }.to "stepOne"

    }

    stepOne{

        on("next") {

        }.to("stepTwo")

        on("cancel").to("finish")

    }

    stepTwo{

        on("next") {

        }.to("stepThree")

        on("previous").to("stepOne")
    }

    stepThree{

        on("next") {

        }.to("stepFour")

        on("previous").to("stepTwo")
    }

    stepFour{

        on("next") {

        }.to("finish")

        on("previous").to("stepThree")
    }

    finish{
        redirect(controller:'patient',action: "list")
    }
}

但是当我导航到第一次转换时,我得到了这个

错误500:内部服务器错误

URI / ivfportal /患者/ newEdit / 3 类 显示java.lang.NullPointerException 信息 空值 在GrailsFlowExecutorImpl.java第74行附近

71:} 72:73:尝试{74:return super.resumeExecution(flowExecutionKey,context); 75:} 76:catch(FlowExecutionRestorationFailureException e){77:if(e.getCause()instanceof SnapshotUnmarshalException){ 在GrailsFlowHandlerAdapter.java的第53行附近

50:request.setAttribute(GrailsApplicationAttributes.CONTROLLER,controllerInstance); 51:} 52:53:return super.handle(request,response,handler); 54:} 55:56:public void setGrailsApplication(GrailsApplication grailsApplication){ 围绕PageFragmentCachingFilter.java的第189行

186:if(method == null){187:log.debug(“找不到{}:{} {}的缓存方法”,188:new Object [] {request.getMethod(),request.getRequestURI (),getContext()}); 189:chain.doFilter(request,response); 190:return; 191:} 192:Collection cacheOperations = cacheOperationSource.getCacheOperations( 在AbstractFilter.java第63行附近

60:尝试{61://为RequestDispatcher转发设置NO_FILTER以避免双重gzipping62:if(filterNotDisabled(request)){63:doFilter(request,response,chain); 64:} 65:else {66:chain .doFilter(req,res); 围绕DevModeSanityFilter.groovy第45行

42:response.contentType =“text / html”43:response.writer<< RELOADING_DOC44:} else {45:chain.doFilter(request,response)46:47:if(request.getAttribute('resources.need.layout')){48:def dispositionsLeftOver = DispositionsUtils.getRequestDispositionsRemaining(request) 在GrailsAnonymousAuthenticationFilter.java的第53行附近

50:51:applyAnonymousForThisRequest((HttpServletRequest)req); 52:53:chain.doFilter(req,res); 54:} 55:56:protected void applyAnonymousForThisRequest(HttpServletRequest request){ 在RestAuthenticationFilter.groovy的第139行附近

任何我出错的地方?在Grails的多页面流中收集数据有一种更简单但更整洁的方法吗?

1 个答案:

答案 0 :(得分:0)

你可以通过对话传递params。 conversation.patient = Patient.get(params.id) 您在Web流程中使用的每个类都必须是可序列化的