LookupDispatchAction

选择dispatch方法的一个方便的方式是将它们连接到按钮,这对于本地化应用来说是个问题,因为按钮的标签可能根据用户的场所来改变,如英文版本显示Delete按纽而对中文用户要显示“删除”

LookupDispatchAction(org.apache.struts.actions.LookupDispatchAction)通过将标签映射到资源文件的消息关键字来解决这个问题,但消息关键字不是相应Java方法的名称,开发人员就提供一个hash表来映射消息关键字和dispatch方法名(通过getKeyMethodMap方法实现)

protected Map getKeyMethodMap(ActionMapping mapping, ActionForm form,
			HttpServletRequest Request) {
		Map map = new HashMap();
		map.put("button.add", "cerate");//把button.add映射到create方法
		map.put("button.view", "read");
		map.put("button.update", "update");
		map.put("button.delete", "delete");
		return map;
	}
public ActionForward create(ActionMapping mapping,
	ActionForm form,
			HttpServletRequest Request, HttpServletResponse Response)
			throws IOException, ServletException;

	public ActionForward read(ActionMapping mapping, 
	ActionForm form,
			HttpServletRequest Request, HttpServletResponse Response)
			throws IOException, ServletException;

	public ActionForward update(ActionMapping mapping, 
	ActionForm form,
			HttpServletRequest Request, HttpServletResponse Response)
			throws IOException, ServletException;

	public ActionForward delete(ActionMapping mapping, 
	ActionForm form,
			HttpServletRequest Request, HttpServletResponse Response)
			throws IOException, ServletException;

JSP中按钮要这样来创建:

<html:form action="/dataRecord">
			<html:submit property="method">
				<bean:message key="button.add">
			</html:submit>
			<html:submit property="method">
				<bean:message key="button.view">
			</html:submit>
			<html:submit property="method">
				<bean:message key="button.update">
			</html:submit>
			<html:submit property="method">
				<bean:message key="button.delete">
			</html:submit>
		</html:form>

对应的资源文件

中文ApplicationResources_zh_CN.properties

button.add=增加

button.view=查看

button.update=更新

button.delete=删除

英文ApplicationResources_zh.properties

button.add=Add

button.view=View

button.update=Update

button.delete=Delete

原文:http://www.rjpx.net/java-peixun/891.html


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值