【问题标题】:Web flow in Grails - confusedGrails 中的 Web 流 - 困惑
【发布时间】:2015-09-03 14:28:47
【问题描述】:

每次接触 web 流时我都感到痛苦,我认为在 grails 的世界中事情可能会像 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/patient/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("No cacheable method found for {}:{} {}",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: try {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

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

有人知道我哪里出错了吗?在 Grails 中是否有一种更简单但仍然整洁的方法来通过多页面流收集数据?

【问题讨论】:

    标签: grails web spring-webflow flow


    【解决方案1】:

    您可以通过对话将参数传递给流程。 对话.患者 = Patient.get(params.id) 您在网络流中使用的每个类也必须是可序列化的

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-09-24
      • 2021-11-09
      • 2019-01-15
      • 1970-01-01
      • 1970-01-01
      • 2015-03-31
      • 2016-06-16
      • 1970-01-01
      相关资源
      最近更新 更多