我升级Spring 2.5中的Web应用程序到Spring 5.0.3。 我使用的字符串形式的标签。 在我的控制,我有:
@InitBinder
public void initBinder(WebDataBinder binder, HttpServletRequest request) {
CapTypeEditor capTypeEditor = new CapTypeEditor(this.getDAOFactory());
binder.registerCustomEditor(CapType.class, "order.capType.id", capTypeEditor);
}
我看这就是所谓的两次(为什么?)对GET和POST上两次。 在搞定,用request.getParameter(“order.capType.id”)为空,在POST同样具有正确的ID。 但后来在我提交()POST方法,capType不为空,但它只有在ID填充,而不是它的名字:
@RequestMapping(value = "/es/orderinfo.html", method=RequestMethod.POST)
public ModelAndView submit(@RequestParam("id") long id,
@ModelAttribute("command")OrderInfoBean bean,
BindingResult errors, ModelMap model,
HttpServletRequest request) {
Order order = bean.getOrder();
CapType ct = order.getCapType();
...
}
我CapType编辑器永远不会被调用:
public class CapTypeEditor extends PropertyEditorSupport {
DAOFactory daoFactory;
public CapTypeEditor(DAOFactory daoFactory){
this.daoFactory = daoFactory;
}
public void setAsText(String text){
if(StringUtils.isBlank(text)||StringUtils.isEmpty(text) ){
this.setValue(null);
return;
}
Long id = Long.valueOf(text);
CapType capType = daoFactory.getCapTypeDAO().read(id);
this.setValue(capType);
}
public String getAsText(Object value){
if(value == null) return StringUtils.EMPTY;
CapType capType = (CapType)value;
return capType.getId().toString();
}
}
我的JSP是这样的:
<form:select path="order.orderType.id" tabindex="100" cssStyle="width:149px">
<form:option value="">none</form:option>
<form:options items="${refData.orderTypes }" itemValue="id" itemLabel="typeName" />
</form:select>