appfuse中使用/common/pickList.jsp来处理多选,在开发的过程中开始照猫总是画不出虎来,后来才发现涉及到好几个地方。
1。pickList.jsp里面使用List<LabelValue>进行处理,因此要进行转换。比如左侧的availableRoles就是在StartupListener中把需要的数据放到context中。右侧的list是在User中提供getRoleList这样的辅助方法来获得。
2。在userForm.jsp中,需要增加下面的js,来保证提交的时候userRoles都被选中,否则数据就提交不上去:
<!-- This is here so we can exclude the selectAll call when roles is hidden -->
function onFormSubmit(theForm) {
selectAll('userRoles');
return validateUser(theForm);
}
以及form提交时调用这个函数:
<form:form commandName="user" method="post" action="editUser.html" οnsubmit="return onFormSubmit(this)" id="userForm">
3。UserFormController中,要对获得的userRoles参数进行处理。