Grails Webflow - 保持流量范围的*外* [英] Grails Webflow - keeping things *out* of flow scope
问题描述
我有一个Grails webflow,看起来像这样: - $ / $>
def childFlow = {
start {
action {
def targets = []
Target.list()。each {target - >
targets.add(new TargetCommand(name:target.name,id:target.id))
}
log.debugtargets are $ targets
[children:targets (''成功')。('selectChild')
}
...
TargetCommand是可序列化的。但我得到这个错误:
$ b $ pre $ 引起:java.io.NotSerializableException:com.nerderg.groupie.donate.Target
由于某些原因,Target.list()中的target对象每个{}闭包正在进入流程范围,我无法弄清楚如何将其标记为瞬态。
我在服务中有一些代码放置在当我不希望他们也是如此。
如何阻止放入流程范围的闭包中的本地瞬态变量?
改进上面的答案而不是清除persistenceContext,我们只是在实例完成后逐出它们,如下所示:
Target.list()。each {
targets.add(new TargetCommand(name:it.name,id:it .id))
flow.persistenceContext.evict(it)
}
这仍然是一个解决方法,不能将闭包变量标记为瞬态
I'm missing something....
I have a Grails webflow that looks like this:-
def childFlow = {
start {
action {
def targets = []
Target.list().each {target ->
targets.add(new TargetCommand(name: target.name, id: target.id))
}
log.debug "targets are $targets"
[children: targets]
}
on('success').to('selectChild')
}
...
TargetCommand is serializable. but I get this error:-
Caused by: java.io.NotSerializableException: com.nerderg.groupie.donate.Target
For some reason the "target" object that is inside the Target.list().each {} closure is getting put into the flow scope, and I can't figure out how to mark it as transient.
I have some code in a Service that has objects placed in the flow scope when I don't want them to too.
How do I stop local transient variables in closures being put in the flow scope?
Refining the above answer instead of clearing the persistenceContext we simply evict the instances as we finish with them, like so:
Target.list().each {
targets.add(new TargetCommand(name: it.name, id: it.id))
flow.persistenceContext.evict(it)
}
This is still a work-around for not being able to mark the closure variables as transient
这篇关于Grails Webflow - 保持流量范围的*外*的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!