jshree
jshree

Reputation: 10411

Wicket pageparameter

I am trying to add and fetch with a key as String and value as List<object> in Wicket PageParameters.

While am fetching the value with key, I got classcastException:String cant be converted into list.

I am using something like this:

List<Example> list = (List<Example>)params.get("ExampleList");

Any help is appreciated.

Upvotes: 4

Views: 4104

Answers (2)

efficacy
efficacy

Reputation: 70

// 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)

Upvotes: 0

Martijn Dashorst
Martijn Dashorst

Reputation: 3682

You can't store objects in PageParameters because PageParameters are an abstraction of HTTP request parameters and the protocol only supports String values. You have to get the list of Strings from the parameters and process it into Example objects.

List<StringValue> values = parameters.getValues("examples");
for(StringValue value : values) {
    Example example = new Example(value.toString());
    examples.add(example);
}

Upvotes: 9

Related Questions