每次接触 web 流时我都感到痛苦,我认为与 Spring MVC 相对的 grails 世界中的事情可能更简单易懂,但似乎并非如此。
我有一个简单的情况,我想在显示 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 = {
}
}
这是我在 Controller 中的流程: 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")
}
}
但是当我导航到第一个转换时,我得到了这个Error 500: Internal Server Error
URI
/ivfportal/patient/newEdit/3
Class
java.lang.NullPointerException
Message
null
Around line 74 of GrailsFlowExecutorImpl.java
71: }72:73: try {74: return super.resumeExecution(flowExecutionKey, context);75: }76: catch (FlowExecutionRestorationFailureException e) {77: if (e.getCause() instanceof SnapshotUnmarshalException) {
Around line 53 of GrailsFlowHandlerAdapter.java
50: request.setAttribute(GrailsApplicationAttributes.CONTROLLER, controllerInstance);51: }52:53: return super.handle(request, response, handler);54: }55:56: public void setGrailsApplication(GrailsApplication grailsApplication) {
Around line 189 of PageFragmentCachingFilter.java
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<CacheOperation> cacheOperations = cacheOperationSource.getCacheOperations(
Around line 63 of AbstractFilter.java
60: try {61: // NO_FILTER set for RequestDispatcher forwards to avoid double gzipping62: if (filterNotDisabled(request)) {63: doFilter(request, response, chain);64: }65: else {66: chain.doFilter(req, res);
Around line 45 of DevModeSanityFilter.groovy
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)
Around line 53 of GrailsAnonymousAuthenticationFilter.java
50:51: applyAnonymousForThisRequest((HttpServletRequest)req);52:53: chain.doFilter(req, res);54: }55:56: protected void applyAnonymousForThisRequest(HttpServletRequest request) {
Around line 139 of RestAuthenticationFilter.groovy
有人看到我哪里出错了吗?在 Grails 中是否有一种更简单但仍然整洁的方法来通过多页面流收集数据?
最佳答案
您可以通过对话将参数传递给流程。
对话.患者 = Patient.get(params.id)
您在 Web 流中使用的每个类也必须是可序列化的
关于grails - Grails 中的 Web 流 - 困惑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32378440/