2006-04-15
自己动手写struts实现下拉框多级联动
约束: 必须以id作为下拉框的value, name为下落框的label;
使用方法: 以三级资料类别为例。
jsp页面:
[code:1] <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>[/code:1]
formBean:
[code:1] private String docTypeL1Id;
/**
* 一级资料类别下拉框选项列表
*/
private ArrayList docTypeL1Options = new ArrayList();
private String docTypeL2Id;
private String docTypeL3Id;[/code:1]
action:
[code:1] /**
* 跳转到“创建资料步骤一”页面。
*
* @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"));
}[/code:1]
SQL.xml:
<!-- 文档模块 SQL语句 -->
[code:1] <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"
/>[/code:1]
使用方法: 以三级资料类别为例。
jsp页面:
[code:1] <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>[/code:1]
formBean:
[code:1] private String docTypeL1Id;
/**
* 一级资料类别下拉框选项列表
*/
private ArrayList docTypeL1Options = new ArrayList();
private String docTypeL2Id;
private String docTypeL3Id;[/code:1]
action:
[code:1] /**
* 跳转到“创建资料步骤一”页面。
*
* @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"));
}[/code:1]
SQL.xml:
<!-- 文档模块 SQL语句 -->
[code:1] <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"
/>[/code:1]







评论排行榜