最开始的设计是这样的:
枚举类代码:
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; // 外观:直板、滑盖、翻盖
至此,完成 。。。
分享到:
相关推荐
struts2标签库struts2标签库struts2标签库struts2标签库
struts2标签使用例子 struts2标签使用例子 struts2标签使用例子struts2标签使用例子
Struts2标签库Struts2标签库Struts2标签库Struts2标签库Struts2标签库Struts2标签库
struts1标签struts1标签struts1标签struts1标签struts1标签struts1标签struts1标签struts1标签struts1标签struts1标签struts1标签struts1标签struts1标签struts1标签struts1标签struts1标签struts1标签
Struts2标签与开发手册 Struts2标签与开发手册 Struts2标签与开发手册 Struts2标签与开发手册
struts2枚举值转换示例。 包括一个自定义枚举值转换器, 一个自定义日期值转换器。 需要用struts2处理枚举值的朋友可以试一下。 包括所有需要的jar包。
主要介绍了struts2的标签的详细使用例子说明
Struts2_控制标签与数据标签.pdf
struts2 标签库介绍(html)对Struts2的标签做了详细的介绍让你轻松掌握Struts2的标签。 STRUTS2学习文档.pdf 对Struts2的一些配置文件进行了详细的说明。 Struts2―表单验证validate(html)对validate的type属性...
Struts2自定义分页标签很详细了,新手可以少走弯路,节约时间 资源包括了后台如何操作。
struts标签库struts标签库struts标签库struts标签库struts标签库struts标签库struts标签库struts标签库
Struts2中实现自定义标签很简单,主要分为3步: 1.创建taglib文件(.tld),编写标签声明。 2.编写自定义标签类。 3.在页面中使用标签。 下面以一个自定义的分页标签为例,进行说明。 其实,开发自定义标签并不...
通过struts2 自定义标签实例,可以用这个对项目中的实现自定义标签。从而减少代码。
struts标签 • Bean Tags:该标签库包含的标签可以用来创建bean、访问bean和访问bean的属性。同时提供了依据cookies、headers和parameters的值创建相关bean的能力。 HTML Tags:该标签库包含的标签可以用来创建...
struts2 jar包 包含 标签
基于struts2的自定义分页标签实现的一个demo,连接数据库为Oracle
STRUTS:struts2标签库
struts 2 s标签 a标签创建一个HTML超链接,等价于HTML 的 示范代码: 登陆</s:a>
struts2 标签使用struts2 标签使用struts2 标签使用struts2 标签使用struts2 标签使用struts2 标签使用
一个struts2的用户管理实例,涉及增删改查。 主要用到的技术: 1.struts2 2.国际化 3.类型转换 4.struts标签