简体   繁体   中英

adding new item in indexed property of struts

here is what i want to do: I have an actionForm with an indexed property(a list of districts), I have managed to show and bind all items to form the list districts.

I want to have a jsp page that allow user to add and delete item in that list. The problem is that struts use for example districts[0], districts[1] to bind each item in the list, when i want new item to be added or deleted, does this mean i need to append new 'input' tag with name='districts[last_index]' at the end of the list using javascript for addition and remove input tags for the corresponding index for deletion? is there alternative for this?

Yes. This is the way it works. I have tried managing parameters like this and has worked fine. And, for the deletion, you need not re-index the items. You just need to manage the last_index. For your information:

If the list contains objects with nested property, you need to implement this. Otherwise, you can just get the items in the list with the listname specified.

Eg:

For List<Integer> integerInputs; , &integerInputs=1&integerInputs=230&integerInputs=332 will work.

For

class MyObj {
      String name;
      int id;
      .
      .
      Getters and Setters
      .
      .
}

List<MyObj> myObjList;

The url to populate the list would be something like &myObjList[0].id=12&myObjList[0].name=testName1&myObjList[1].id=122&myObjList[1].name=testNameOnly

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM