最开始的设计是这样的:
枚举类代码:
public enum Face {
STRAIGHT {
public String getName() {
return "直板";
}
},
COVER {
public String getName() {
return "翻盖";
}
},
SLIP {
public String getName() {
return "滑盖";
}
};
public abstract String getName();
public static Map<String, String> getMap() {
Map<String, String> maps = new HashMap<String, String>();
Face[] faces = Face.class.getEnumConstants();
for (Face f : faces) {
maps.put(f.toString(), f.getName());
}
return maps;
}
}
前台jsp页面对应的引用为:
<s:radio list="@com.asm.product.mobile.entity.Face@getMap()" name="mobile.face"></s:radio>
这样设计有两个问题:
(1):不能为此标签设定一个默认值(2)如果修改导航过来,不能还原
改进设计:
步骤一:在枚举类中把getMap改成非静态的。
步骤二:前台jsp页面对应的引用为:
<s:radio list="mobile.face.getMap()" name="mobile.face"></s:radio>
步骤三,在导向到此jsp页面就设置初始化信息,即:
public String addUIProduct() throws Exception {
mobile = new Mobile();
return "addUI";
}
说明:moile对象持有枚举类Face,并且要初始化一个值:
private Face face = Face.STRAIGHT; // 外观:直板、滑盖、翻盖
至此,完成 。。。