【问题标题】:Spring FlashScope弹簧闪光灯
【发布时间】:2011-03-17 20:40:12
【问题描述】:

在等待 FlashScope 集成到 Spring 3.1 中(无论如何都计划在此版本中)时,我遇到了this bug posting,这让我可以整合 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 简单地包装到另一个对象中可以解决问题吗?

【问题讨论】:

    标签: java data-binding spring-mvc velocity flash-scope


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2014-12-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-27
      • 2012-03-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多