概述
Java代码
- @InitBinder
- public void initBinder(WebDataBinder binder) {
- SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
- dateFormat.setLenient(false);
- binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
- binder.registerCustomEditor(SystemInfo.class, new PropertyEditorSupport() {
- @Override
- public void setAsText(String text) throws IllegalArgumentException {
- if (!StringUtils.hasText(text)) {
- return;
- }
- {
- Long systemInfoId = Long.valueOf(text);
- SystemInfo systemInfo = systemInfoService.findById(systemInfoId);
- setValue(systemInfo);
- }
- }
- });
- binder.registerCustomEditor(Category.class, new PropertyEditorSupport() {
- @Override
- public void setAsText(String text) throws IllegalArgumentException {
- if (!StringUtils.hasText(text)) {
- return;
- } else {
- Long categoryId = Long.valueOf(text);
- Category category = categoryService.findById(categoryId);
- setValue(category);
- }
- }
- });
- }
Html代码
- <form:form modelAttribute="categoryEditForm" id="categoryForm" method="post" action="saveOrUpdate.do">
- <form:hidden path="category.objectId" />
- <input type="hidden" name="category.parent" value="${categoryEditForm.category.parent.objectId}"/>
- <input type="hidden" name="category.systemInfo" value="${categoryEditForm.category.systemInfo.objectId }"/>
- <div class="area">
- <div class="areaTitle">
- <div class="inner">
- <label>Category Information Form</label>
- <div class="clear"></div>
- </div>
- </div>
- </div>
- <div class="areaBody">
- <table class="formTable">
- <tbody>
- <tr>
- <td colspan="4">
- <span class="button"><span><a href="javascript:sumbit();" class="btnSave">Submit</a></span></span>
- </td>
- </tr>
- <tr>
- <td colspan="4"> </td>
- </tr>
- <tr>
- <td align="right">Parent Category Name:</td>
- <td colspan="3"><form:input path="category.parent.name.fullName" readonly="true" id="parentCategory" cssClass="input readOnly" /></td>
- </tr>
- <tr>
- <td align="right">Current Category Name:</td>
- <td><form:input path="category.name.fullName" id="categoryName" cssClass="input"/></td>
- <td align="right">description:</td>
- <td><form:input path="category.description" id="description" cssClass="input"/></td>
- </tr>
- </tbody>
- </table>
- </div>
- </form:form>
最后
以上就是背后过客为你收集整理的@InitBinder使用的全部内容,希望文章能够帮你解决@InitBinder使用所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复