html:options是Struts中比较复杂的一个tage lib,用法灵活,但是Sturts提供的源码exercise taglib中没有提出常用jsp+ActionForm这样形式的最直接的总结,现从中总结如下,分两种情况:数组和Collection。
需求,要达到:
<select name="beanCollectionSelect" multiple="multiple" size="10"><option value="Value 0">Label 0</option>
<option value="Value 1" selected="selected">Label 1</option>
<option value="Value 2">Label 2</option>
<option value="Value 3" selected="selected">Label 3</option>
<option value="Value 4">Label 4</option>
<option value="Value 5" selected="selected">Label 5</option>
<option value="Value 6">Label 6</option>
<option value="Value 7">Label 7</option>
<option value="Value 8">Label 8</option>
<option value="Value 9">Label 9</option></select>
"Label 0", "Value 0"));
entries.add(new LabelValueBean("Label 1", "Value 1"));
entries.add(new LabelValueBean("Label 2", "Value 2"));
entries.add(new LabelValueBean("Label 3", "Value 3"));
entries.add(new LabelValueBean("Label 4", "Value 4"));
entries.add(new LabelValueBean("Label 5", "Value 5"));
entries.add(new LabelValueBean("Label 6", "Value 6"));
entries.add(new LabelValueBean("Label 7", "Value 7"));
entries.add(new LabelValueBean("Label 8", "Value 8"));
entries.add(new LabelValueBean("Label 9", "Value 9"));
"Single 5";
public String getSingleSelect() {
return (this.singleSelect);
}
public void setSingleSelect(String singleSelect) {
this.singleSelect = singleSelect;
}
"Value 1", "Value 3",
"Value 5" };
public String[] getBeanCollectionSelect() {
return (this.beanCollectionSelect);
}
public void setBeanCollectionSelect(String beanCollectionSelect[]) {
this.beanCollectionSelect = beanCollectionSelect;
}
"beanCollectionSelect" size="10" multiple="true">
<html:optionsCollection name="testbean" property="beanCollection"/>
</html:select>
"Magazine", "Journal", "News Paper","Other" };
private String labels[] =
{ "L-Magazine", "L-Journal", "L-News Paper","L-Other"};
private String selected = "Magazine";
public String getSelected(){
return selected;
}
public void setSelected(String selected){
this.selected = selected;
}
public String[] getValues(){
return values;
}
public void setValues(String[] values){
this.values = values;
}
public String[] getLabels(){
return values;
}
public void setLabels(String[] labels){
this.labels = labels;
}
"selected" >
<html:options name="testbean" property="values" labelProperty="label"/>
</html:select>
Vector entries = new Vector(10);
entries.add(new LabelValueBean(
private String singleSelect =
private String[] beanCollectionSelect = {
<html:select property=
private String values[] =
{
<html:select property=
最新相关文章
发表评论