自己动手写struts实现下拉框多级联动

约束: 必须以id作为下拉框的value, name为下落框的label;

使用方法: 以三级资料类别为例。

jsp页面:
		<tr class="whitebg">
<td width="15%" height="20" class="gray">文档类型<span class="redStar">*</span></td>
<td>
<html:select property="docTypeL1Id"
onchange="setProperty('docTypeL2Id','');;setProperty('docTypeL3Id','');;refreshPage(this);">
<option value=""><bean:message key="label.pleaseSelect" bundle="common" /></option>
<html:optionsCollection property="docTypeL1Options" />
</html:select>
<html:select property="docTypeL2Id"
onchange="setProperty('docTypeL3Id','');;refreshPage(this);">
<option value=""><bean:message key="label.pleaseSelect"
bundle="common" /></option>
<xxx:dynamicOptions parentProperty="docTypeL1Id"
sqlModule="module_doc" sqlName="sql_doc_options_doctypel2" />
</html:select>
<html:select property="docTypeL3Id"
onchange="refreshPage(this);">
<option value=""><bean:message key="label.pleaseSelect"
bundle="common" /></option>
<xxx:dynamicOptions parentProperty="docTypeL2Id"
sqlModule="module_doc" sqlName="sql_doc_options_doctypel3" />
</html:select></td>
</tr>



formBean:
	private String docTypeL1Id;
/**
* 一级资料类别下拉框选项列表
*/
private ArrayList docTypeL1Options = new ArrayList();;
private String docTypeL2Id;
private String docTypeL3Id;


action:
	/**
* 跳转到“创建资料步骤一”页面。
*
* @param mapping
* @param form
* @param request
* @param response
* @return
*/
public ActionForward showCreateDocStep1(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response);
throws Exception {
DocForm docForm = (DocForm); form;
DocDelegate docDelegate = new DocDelegate();;

//设置当前左菜单栏的焦点
BarFocus.setFocus(request, BarFocus.PW_CREATE_DOC);;
//进入页面之前需要把第一级资料类别下拉框的数据准备好。
DocViewHelper.prepareViewHelpData(docForm);;
return mapping.findForward("createDocStep1");;
}

//刷新页面执行的方法, 也可调用showCreateDocStep1
public ActionForward refreshPage(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response);
throws Exception {
DocViewHelper.prepareViewHelpData((DocForm); form);;
return (mapping.findForward("createDocStep1"););;
}



SQL.xml:

<!-- 文档模块 SQL语句 -->
   <module_doc
sql_doc_options_doctypel2="SELECT * FROM T_BASE_DOC_TYPE WHERE DOC_TYPE_LEVEL='2' AND PARENT_ID=? ORDER BY NAME ASC"
sql_doc_options_doctypel3="SELECT * FROM T_BASE_DOC_TYPE WHERE DOC_TYPE_LEVEL='3' AND PARENT_ID=? ORDER BY NAME ASC"
/>
展开阅读全文

没有更多推荐了,返回首页