我试图用Wicket PageParameters
中的密钥String
和值List<object>
来添加和获取。Wicket页面参数
虽然我的读取与键的值,我得到了classcastException:String cant be converted into list.
我使用的是这样的:
List<Example> list = (List<Example>)params.get("ExampleList");
任何帮助表示赞赏。
我试图用Wicket PageParameters
中的密钥String
和值List<object>
来添加和获取。Wicket页面参数
虽然我的读取与键的值,我得到了classcastException:String cant be converted into list.
我使用的是这样的:
List<Example> list = (List<Example>)params.get("ExampleList");
任何帮助表示赞赏。
由于PageParameters
是HTTP请求参数的抽象,且协议仅支持String
值,所以不能存储PageParameters
中的对象。您必须从参数中获取字符串列表并将其处理为Example
对象。
List<StringValue> values = parameters.getValues("examples");
for(StringValue value : values) {
Example example = new Example(value.toString());
examples.add(example);
}
谢谢。我会试试这个并且标记这个答案。 – jshree
我不明白这个评论中的一些事情。我认为这一行应该是String values = parameters.get(“examples”);因为参数get方法返回“string”。我无法分配给列表。即使我从get()mthd获得String数组,我也不能将字符串对象指定为Example对象实例。在Example类构造函数中可能不需要“Value.toString”。所以我不知道这个解决方案是否可行。如果我错了,请让我知道。 – jshree
我的示例使用代码Wicket 1.5,其中'PageParameters'的API已更改。 –
// Populate PageParameters
final String dynamicValue = textFieldID.getModelObject();
PageParameters pageParameters = new PageParameters();
pageParameters.add("username", usernameValue);
pageParameters.add("username", "fixedValue");
// Retrieving PageParameters
String newValue = parameters.getValues("username").get(1).toString();
// here newValue will contain "fixedValue" (the second element)
你一起工作什么版本? –
你可以显示与参数填充对应的代码片段吗? –