目标:实现分类的下拉菜单,例如车型是属于某个品牌的某个车型.
1 <html:select property="brandId">
2 <html:optionsCollection name="brands" value="id" label="name"/>
3 </html:select>
首先是添加时要初始化brands:
1 @Override
2 protected void refrenceData(HttpServletRequest request) {
3 request.setAttribute("brands", modelManager.getBrand());
4 }
其次是修改时要在下拉菜单显示已选值:
1 protected void onInitForm(ActionForm form, HttpServletRequest request,TModel model) {
2
3 if (model.getBrand() != null) {
4 LazyValidatorForm bookForm = (LazyValidatorForm) form;
5 bookForm.set("brandId",model.getBrand().getId());
6 }
7 }
问题:在添加时要注意不是model!=null,而是model的brand!=null才赋值
posted on 2007-04-24 20:44
NG 阅读(275)
评论(0) 编辑 收藏