Struts2 checkboxlist echo selected question


Use .split(",") to split the value obtained from the previous selection with checkboxlist, that is, a string (this string is connected by ",") to obtain a string array String[] borrowArr, put the array in Take out the elements one by one, it is best to traverse each element with .trim() to remove possible spaces, and put the taken data in the List collection. Then put the list in the request scope.
request.setAttribute("list",borrowArr );


The above is the processing in the action, and no additional setter/getter methods are required for borrowArr.

 On the JSP page, the value of the checkboxlist is: value="#request.borrow".
 This is OK, the checkbox can echo the selected



    String borrowStr="1, 2  ,3 , 4";
    String[] borrowArr = borrowStr.split(",");
    List list = new ArrayList();
    for(int i = 0;i < borrowArr.length; i++)
    {
        list.add(borrowArr[i].trim());
    }
    request().setAttribute("borrow", list);


<s:checkboxlist name="borrow" id="borrow" theme="simple"
    list="#{1:'credit mark',2:'net value mark',3:'day mark',4:'guarantee mark',5:'mortgage mark'}"
    listKey="key" listValue="value" value="#request.borrow">
</s:checkboxlist>

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326641282&siteId=291194637