STRUTS2级联下拉框间如何换行方法源码,strutsxml配置文件,级联下拉框间的换行br 问题。
<%@ taglib prefix=”s” uri=”/struts-tags” %> <%@ page language=”java” errorPage=”/error.jsp” pageEncoding=”GBK” contentType=”text/html;charset=GBK” %> <html> <head> <title>Struts 2 Cool Tags - <s:doubeselect/ ></title> <s:head /> </head> <body> <h2>Doubleselect Tag Example</h2> <s:form action=”doubleSelectPost” name=”form1″> Doubleselect演示1 <s:set name=”technology” value=”#{ ‘Java’: {’Spring’, ‘Hibernate’, ‘Struts 2′}, ‘.Net’: {’Linq’, ‘ ASP.NET 2.0′}, ‘Database’: {’Oracle’, ‘SQL Server’, ‘DB2′, ‘MySQL’} }” /> <s:doubleselect label=”技术选择” list=”#technology.keySet()” name=”doubleselect1″ doubleName=”techdetail” formName=”form1″ doubleList=”#technology[top]” /> <br/><br/> Doubleselect演示数据演示2: <s:set name=”mymap” value=”#request.map”/> <s:doubleselect list=”#request.map.keySet()” doubleName=”mymap1″ name=”doubleselect2″ formName=”form1″ doubleList=”#request.map[top]” label=”Map Test” /> <s:submit/> </s:form> </body> </html>
doubleselectpost.jsp
<%@ taglib prefix=“s” uri=“/struts-tags” %> <%@ page language=“java” errorPage=“/error.jsp” pageEncoding=“GBK” contentType=“text/html;charset=GBK” %> <html> <head> <title>Struts 2 Cool Tags - <s:doubeselect/ ></title> <s:head /> </head> <body> <h2>Doubleselect Tag Example</h2> <s:form name=“form1″> <table border=“0″ cellspacing=“0″ cellpadding=“1″> <tr> <th>参数值</th> </tr> <s:iterator value=“#request.map.keySet()” status=“keys”> <tr> <td><s:property/></td> </tr> </s:iterator> </s:form> </body> </html>
3、struts.xml配置文件实例
<action name=”doubleSelectTest” method=”doubleSelectTest” class=”com.mobilesoft.esales.webapp.action.DoubleListAction”> <result name=”success”>test/doubleselect.jsp</result> </action> <action name=”doubleSelectPost” method=”doubleSelectPost” class=”com.mobilesoft.esales.webapp.action.DoubleListAction”> <result name=”success”>test/doubleselectpost.jsp</result> </action>
4、STRUTS2级联下拉框间的换行<br >问题
在缺省时候,两个级联下拉框间是可以换行的,Struts2使用Freemarker来做模板,通过修改模板来定制标签缺省的树形。参考“Struts2中Datetimepicker控件的中文问题”中的方法,也即:
- 修改struts.mxl,增加如下内容。
<constant name=”struts.serve.static” value=”false” />
<constant name=”struts.ui.templateDir” value=”struts” />
注意在struts2-core-2.0.11.jar/org/apache/struts2/default.properties中有几个与Freemarker对应的配置参数:
struts.ui.theme=xhtml
struts.ui.templateDir=template
#sets the default template type. Either ftl, vm, or jsp
struts.ui.templateSuffix=ftl
- 覆盖缺省的静态文件
在resource目录(与WEB-INF同级或WEB-INF下)创建struts目录,并:
解压struts2-core-2.0.11.jar:/org/apache/struts2/static/ to /struts/
解压struts2-core-2.0.11.jar:/template/simple/ to /struts/simple/
解压struts2-core-2.0.11.jar:/template/xhtml/ to /struts/xhtml/
解压struts2-core-2.0.11.jar:/template/css_xhtml/ to /struts/css_xhtml/
解压struts2-core-2.0.11.jar:/template/ajax/ to /struts/ajax/
解压struts2-core-2.0.11.jar:/template/archive/ to /struts/archive
最后的目录结构如下:
struts/
- ajax/
- archive/
- css_xhtml/
- dojo/
- nls/
- src/
- animation/
- …
- xml/
- struts/
- widget/
- widgets/
- niftycorners/
- simple/
- xhtml/
- 修改doubleselect的模板doubleselect.ftl
修改struts/simple/doubleselect.ftl去除其中的<br />