1

在等待 FlashScope 被集成到 Spring 3.1 中(无论如何都计划在这个版本中)时,我遇到了这个错误发布,它允许我合并一个松散的版本,一旦 3.1 出来就应该可用。

我的问题是我似乎无法绑定到 Flash Scope 中的值。因此,例如在我的模型中,我有以下代码:

ModelAndView mav = new ModelAndView(someInjectedRedirectPage);
//Processing
mav.addObject("flashScope.someVar", someObject);

在我的 UI 中,使用 Velocity,我尝试通过以下方式绑定到该对象:

##This is a velocimacro for those not familiar with velocity.
##It is basically like setting a path on a field utilizing the
##spring tag lib (e.x. <form:text path="flashScope")

#springBind("flashScope") 

但是,当我尝试使用该绑定时,出现以下异常:

java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'flashScope' available as request attribute
at org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:141)
at org.springframework.web.servlet.support.RequestContext.getBindStatus(RequestContext.java:720)bean name 'flashScope' available as request attribute...

但是在我的日志中,我可以清楚地声明它已被添加到请求中。我还可以执行以下操作:

$flashScope.someVar.someProperty #The value prints fine this way.

无论如何要绑定到 Map 值(不在支持命令对象上,而只是在请求上)?

请注意是否执行以下操作:

Map<String, String> map = new HashMap <String, String>(); 
map.put("key", "value");
mav.addObject("map", map);

我仍然无法绑定到地图...

我可以通过扩展 WebBindingInitializer 来修改这种行为吗?将 FlashScopeMap 简单地包装到另一个对象中可以解决问题吗?

4

1 回答 1

0

包裹到另一个对象是我能够解决这个问题的唯一方法。

于 2011-04-25T19:33:18.047 回答