最近使用webwork 2.2.7,遇到一个奇怪的问题,我的action中初始化了一个包含某对象的list,这个list用来填充页面表单中的一个下拉择框控件中的值,但是页面上始终得不到这个list的值,用<ww:if>检查这个list,结果这个list是空的。
以下是我的关于webwork的配置信息:
webwork.properties
webwork.i18n.encoding=UTF-8 webwork.i18n.reload=true webwork.devMode = true webwork.configuration.xml.reload=true webwork.objectFactory = spring webwork.locale=zh_CN webwork.url.http.port = 8080 webwork.custom.i18n.resources=tenancy #webwork.ui.theme=xhtml webwork.ui.theme=simple webwork.ui.templateDir=template #sets the default template type. Either vm or jsp webwork.ui.templateSuffix=ftl webwork.tag.altSyntax=false
xwork.xml
<!DOCTYPE xwork PUBLIC "-//OpenSymphony Group//XWork 1.1.1//EN" "http://www.opensymphony.com/xwork/xwork-1.1.1.dtd"> <xwork> <include file="webwork-default.xml"/> <include file="config-browser.xml"/> <package name="default" extends="webwork-default" > <action name="carInfoAction" class="stu.tenancy.action.CarInfoAction"> <result name="success" type="redirect">/pages/carInfo.jsp</result> <result name="input" type="redirect">/pages/carInfoDetail.jsp</result> </action> </package> </xwork>
CarInfoAction.java
public class CarInfoAction extends ActionSupport{ ....... private String actionName; private IBranchManager branchManager; //所属分店 private List<Branch> branchList = new ArrayList<Branch>(); ......... public String execute(){ if(actionName.equals("listAll")||actionName.equals("cancel")) return SUCCESS; else if(actionName.equals("add")||actionName.equals("edit")){ ......... initBranch(); return INPUT; } else if(actionName.equals("del")) //do some delet action here return SUCCESS; else if(actionName.equals("save")) //do some save action here return SUCCESS; return null; } private void initBranch() { List<Branch> ret = branchManager.getBranchList(); // 这里从数据库中查出需要填充 branchList 的数据,是有值的!! setBranchList(ret); } public List<Branch> getBranchList() { return branchList; } private void setBranchList(List<Branch> branchList) { this.branchList = branchList; } //actionName, branchManager 的get/set方法省略 .......... }
carInfoDetail.jsp
............... <form name="from1" id="form1" method="post"> <ww:token /> <ww:hidden name="carInfo.id"/> <ww:hidden name="'focusCarInfo'" value="carInfo.licensePlaterNum"/> <input type="hidden" name="changed" value="false" /> <table class="details-table" bgcolor="#FAFAF1" > <tr> <td > <LABEL for="carInfo.licensePlaterNum"><ww:text name="'ui.carinfo.detail.licensePlaterNum'"/></LABEL>: <input name="carInfo.licensePlaterNum" id="licensePlaterNum" onchange="touched()" type="text" class="field" value="<ww:property value="carInfo.licensePlaterNum"/>" style="width: 180px" maxlength="50" /> </td> <td> <LABEL for="carInfo.carType"><ww:text name="'ui.carinfo.detail.carType'"/></LABEL>: <ww:select name="carInfo.carType" id="carType" list="typeList==null? {}:typeList" required="true" emptyOption="true" cssStyle="'width:150px'" cssClass="'genselect'" listKey="id" listValue="name"/></td> <td><LABEL for="carInfo.affiliatedCompany"><ww:text name="'ui.carinfo.detail.affiliatedCompany'"/></LABEL>: // 需要填充的下拉选择框控件 <ww:select name="carInfo.affiliatedCompany" id="affiliatedCompany" list="branchList==null?{}:branchList" required="true" emptyOption="true" cssStyle="'width:150px'" cssClass="'genselect'" listKey="id" listValue="name" /></td> // 这里是用来测试 branchList 是否得到了!!! <ww:if test="branchList==null"> <ww:select name="domain.sex" label="性别" list="#{'男':'男','女':'女'}" value="domain.sex.charAt(0)" emptyOption="true" required="true"> </ww:select> </ww:if> .................
List<Branch> branchList = new ArrayList<Branch>() 中,Branch 类中有属性 id, name, 不知以上写法是否正确,能否遍历出 branchList 里的branch对象并用
id, name 填充select控件的option。
我的测试页面上是得不到那个branchList 的,请问各位谁有过类似的经验,能否指点一下。在此先表示感谢!!