(1) struts1中select的三种写法
1 以前经常用的方式
<html:select styleId="categoryName" name="productForm" property="productcategory.id" value="${categoryId}" >
<logic:iterate id="p" name="productForm" property="productcategoryList">
<html:option value="${p.id}"><bean:write name="p" property="name"/></html:option>
</logic:iterate>
</html:select>
2 html:optionsCollection
productcategoryList为ActionForm的属性,使用html:optionsCollection
<html:select styleId="categoryName" name="productForm" property="productcategory.id">
<html:optionsCollection name="productForm" property="productcategoryList" label="name" value="id" />
</html:select>
3 html:options
productcategoryList作为request的一个属性传到页面上,则使用html:options
<html:select styleId="categoryName" name="productForm" property="productcategory.id">
<html:options collection="productcategoryList" labelProperty="name" property="id"/>
</html:select>
(2)struts1中设置选中默认值,${categoryId}为request传到页面上的值.
<html:select styleId="categoryName" name="productForm" property="productcategory.id" value="${categoryId}" >
<html:optionsCollection name="productForm" property="productcategoryList" label="name" value="id" />
</html:select>
(3)struts1中radio选中默认值
<html:radio value="0" property="product.issale" name="productForm">不上架</html:radio>
<html:radio value="1" property="product.issale" name="productForm">上架</html:radio>
在XXForm中添加issale属性以及set和get方法,在页面就会默认选中value为0的选项。
public class XXForm {
public void reset(ActionMapping mapping, HttpServletRequest request) {
super.reset(mapping, request);
product = new CProducts();
product.setIssale("0");
}
public String getIssale() {
return issale;
}
public void setIssale(String issale) {
this.issale = issale;
}
}