views:

245

answers:

1

Hi all, I'm a jstl newbie so probably this question will sound to you funny. Anyway, I have a model with a List as property and I'd like to fill this with a list of values (chosen from a list of checkboxes). I'm using the useBean tag in the form-processing jstl page, but doing this:

<jsp:useBean id='subscription' class='Subscription'>
<c:set target='${subscription}' property='priviledge' value='${param.priviledge}'/>

Where the property priviledge is a List and $param.priviledge the values of a series of checkboxes, I get a

javax.servlet.jsp.el.ELException: Attempt to convert String "ads"  to type "[Ljava.lang.String;", but there is no PropertyEditor for that type

"ads" is one of the values I have selected. I thought the values of the priviledge field was already a List but it seems it works in a different way. I tried to iterate through the $param.priviledge object and I get all the values with no problem.

How can I use this list to fill a List?

Thanks for any help. Roberto

+1  A: 

Attempt to convert String "ads" to type "[Ljava.lang.String;"

This error suggests that the setter is setPriviledge(String[] arr), not a java.util.List.

The values in the param map are Strings; to get all the values as an array, use the paramValues map.

${paramValues.priviledge}

The property on the Subscription bean would need to be a String array:

  private String[] priviledge;

  public String[] getPriviledge() {
    return priviledge;
  }

  public void setPriviledge(String[] priviledge) {
    this.priviledge = priviledge;
  }

(I don't know if you've simplified the code to post here, but you should not use the default package - many web servers won't like it and won't be able to instantiate your Subscription class.)

McDowell
Brilliant. Thanks for the explanation, didn't know about the paramValues object.ps: yes I wrote it simplified, my model is not using the default package :)
Roberto