I have a problem in getting checkbox's value from JSP. I used SpringMVC, and my related class as follows:
Form:
@Getter @Setter
public class Sample3Form extends AbstractForm {<
private List<Sample1Bean> sampleList; //all data
private ValidPagedListHolder<Sample1Bean> samplePagedList;//1 page data
}
Sample1Bean:
@Getter @Setter
public class Sample1Bean extends AbstractOnlineDataBean {
private String keiyakuno;
private String keiyakunm;
private String torisakino;
}
Parent Bean Class:
@Getter
@Setter
public abstract class AbstractOnlineDataBean extends AbstractDataBean {
private Integer selectedIndex;
private String maskPattern;
}
Controller:
@Controller
@RequestMapping(value = "app/sample3")
@SessionAttributes(value = "sample3Form")
@NotCheckToken
public class SampleController3 extends AbstractController {
private static Logger logger = LoggerFactory.getLogger(UserUtil.class);
@ModelAttribute(value = "sample3Form")
public Sample3Form getForm() {
return new Sample3Form();
}
......
......
@RequestMapping(value = "delete")
public String delete(Model model, @Validated Sample3Form form, BindingResult result, HttpServletRequest request) throws GdcSystemException {
List<Sample1Bean> list = new ArrayList<Sample1Bean>();
int size = form.getSampleList().size();
ValidPagedListHolder<Sample1Bean> plist = form.getSamplePagedList();
list = plist.getPageList();
for (int i = 0 ; i < size; i ++) {
if (form.getSampleList().get(i).getSelectedIndex() == null ) {
} else {
//I cannot arrive here even though I checked in JSP
list.add(form.getSampleList().get(i));
}
}
...
...
}
JSP:
<ab:form id="sample3" action="submit" modelAttribute="sample3Form">
<table width="100%" class="tableborder" cellpadding="0" cellspacing="0">
...
...
<ab:tr index="${row.index}">
<td width="2%" class="data_list_area">
<ab:checkbox path="${sample3Form.samplePagedList.pageList[row.index].selectedIndex}" fwformat='NONE'
value="${sample3Form.samplePagedList.page * sample3Form.samplePagedList.pageSize + row.index }" name="checkedids"/>
</td>
<td width="5%" class="data_list_area">
<!--ab:out value="${sample3Form.samplePagedList.pageList[row.index].keiyakuno}" /-->
<ab:label path="" fwformat='NONE'>${sample3Form.samplePagedList.pageList[row.index].keiyakuno}</ab:label>
</td>
...
...
In above JSP, I set checkboxes and bind the checkboxes to selectedIndex property for for every row data.but i cannot get selected row in controller as follows:
form.getSampleList().get(i).getSelectedIndex()
The return value is always null. why? Could who please tell me how i can get the selectedIndex in controller?
By the way, I can get checked row in controller like below:
String[] arr = request.getParameterValues("checkedids");
Note: in JSP, added checkboxes is defined by name "checkedids".
Thanks.
Aucun commentaire:
Enregistrer un commentaire