0

I have list box in my JSP page which is getting populated by object which is passed from controller side. I want to choose some items and press DELETE button to remove some items from my black list. (Update property)

<select name="blackListSelect" id="blackListSelect" >
    <c:forEach var="entry" items="${blackList}">
        <option value='${entry.id}'>${entry.value}</option>
    </c:forEach>
</select>


public class Site
{
   int SiteId;
   List<BlackWord> blackList;

....
...
..

}

How do I update my blackList property on server side? how do I pass this object back? How should I bind updated list back to property? Could you please give me any tips or code example? Thanks!

Wild Goat
  • 3,509
  • 12
  • 46
  • 87

1 Answers1

1

It is not straight forward: you can't pass back the all the entries of select if you just do POST on a form. There are several ways to do what you want:

  1. The POST will pass selected items. The back end code then will have to reconcile the list accordingly
  2. Pass all the remaining select items in select on DELETE. The JavaScript function will have to get them.
jny
  • 8,007
  • 3
  • 37
  • 56
  • Thanks a lot. Could you please show me example how I pass javaScript object to back end code? For example I have var `blacklist = ["abc","cba"]` How do I access it in controller? Thanks! – Wild Goat Oct 07 '13 at 14:18
  • The easiest way is to have a hidden field and put the values in it. Are you using any JavaScript libraries? – jny Oct 07 '13 at 14:25
  • I am using jQuery and jstl taglib plugged in. Thanks! – Wild Goat Oct 07 '13 at 14:29
  • Check http://stackoverflow.com/questions/2408043/jquery-create-hidden-form-element-on-the-fly for ideas on how to add hidden elements using jquery – jny Oct 07 '13 at 16:07