无法使用弹簧数据function绑定数据

线程继续发送数据回到控制器spring-mvc

我正在制作一个产品详细信息页面,我需要向用户显示一些选项,用户将选择其中的一些,并且在提交按钮上的产品应该添加到购物篮中。 我的目的是将Data对象传输到Cart Controller,以便我可以使用这些值,因为对象包含动态值,因此无法定义预先确定的field对象。 这是我的数据对象

public class PrsData { private Map<String, List> prsCDData; public PrsData(){ this.prsCDData = MapUtils.lazyMap(new HashMap<String, List>(), FactoryUtils.instantiateFactory(PrsCDData.class)); } } public class PrsCDData { private Map<String, List> configuredDesignData; // same lazy map initialization } 

在我的产品详细信息页面控制器中,我将值设置为:

 model.addAttribute("prsData", productData.getPrsData()); 

在我的产品详细信息页面JSP上我有以下forms:

 

但是,当我点击提交按钮时,我收到以下exception

 org.springframework.beans.InvalidPropertyException: Invalid property 'prsCDData['Forced'][0]' of bean class [com.product.data.PrsData]: Property referenced in indexed property path 'prsCDData['Forced'][0]' is neither an array nor a List nor a Set nor a Map; returned value was [com.product.data.PrsCDData@6164f07e] 

我不确定我在哪里做错了,因为在产品详细信息页面上这些隐藏字段正确绑定并且分配了偶数值但是当表单提交时我面临这个问题。

LazyMap工厂必须返回一个LazyList。

给定的工厂FactoryUtils.instantiateFactory(PrsCDData.class)创建一个新的PrsCDData对象而不是PrsCDData的List。

 prsCDData['Forced'] -> if exists then return it else create instance of PrsCDData.class 

应该

 prsCDData['Forced'] -> if exists then return it else create instance of LazyList 

使用LazyList,因为您立即想要访问索引’0’,否则会导致ArrayIndexOutOfBoundsExecption

编辑:简单的例子

 public class Test { @SuppressWarnings("unchecked") public static void main(String[] args) throws UnsupportedEncodingException { Map> map = MapUtils.lazyMap(new HashMap>(),new Factory() { public Object create() { return LazyList.decorate(new ArrayList(), FactoryUtils.instantiateFactory(SimpleBean.class)); } }); System.out.println(map.get("test").get(0)); } public static class SimpleBean { private String name; } }