Struts2 devMode使用“键"时异常提交标签中的属性 [英] Struts2 devMode Exception when using "key" attribute in submit tag

查看:87
本文介绍了Struts2 devMode使用“键"时异常提交标签中的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在打开devMode的情况下使用Struts2,以捕获尽可能多的警告和错误.现在,我遇到了一些严重通知,仅在devMode中得到了通知.

I'm using Struts2 with devMode turned on to catch as many warnings and errors as possible. Now I got across with some SEVERE notification that is only notified in devMode.

我正在使用submit标记,并且添加了 key 属性,以从名为global.BOTON_LOGIN的属性中获取按钮文本"Entrar".该按钮是窗体的一部分,该窗体调用映射到类actions.LoginAction:

I'm using the submit tag and I include the key attribute to get the button text "Entrar" from a property called global.BOTON_LOGIN. The button is part of a form that calls an action mapped to the class actions.LoginAction:

<s:submit key="global.BOTON_LOGIN" type="button" />

该按钮的文本正确显示,当我按此按钮时,一切正常,除了在日志中显示以下严重通知:

The text of the button displays correctly and when I push this button everything works fine, except for this SEVERE notification showing up in the log:

30-Mar-2015 00:46:37.855 SEVERE [http-apr-8080-exec-146] com.opensymphony.xwork2.util.logging.jdk.JdkLogger.error Developer Notification (set struts.devMode to false to disable this message): Unexpected Exception caught setting 'global.BOTON_LOGIN' on 'class actions.LoginAction: Error setting expression 'global.BOTON_LOGIN' with value ['Entrar', ]

我注意到为按钮生成的HTML代码是:

I have noticed that the HTML code generated for the button is:

<button type="submit" id="login_global_BOTON_LOGIN" name="global.BOTON_LOGIN" value="Entrar">Entrar</button>

要摆脱该SEVERE条目,我的解决方法是使用value属性和getText方法而不是key属性:

My workaround to get rid of that SEVERE entry is to use the value attribute and the getText method instead of the key attribute:

<s:submit value="%{getText('global.BOTON_LOGIN')}" type="button" />

依次生成HTML代码:

which in turn generates that HTML code:

<button type="submit" id="login_0" value="Entrar">Entrar</button>

严重"通知消失了.

在第一种情况下我有做错什么吗?

Is there something I do wrong in the first case?

推荐答案

您使用的key属性值未将提交"按钮绑定到操作. Struts UI标记通常将name属性的值绑定到操作.根据Struts文档页面,key 参数

You have used a key attribute's value that didn't bind a submit button to the action. Struts UI tags usually bind the name attribute's value to the action. According to Struts docs page a key parameter is

为此特定组件设置键(名称,值,标签)

Set the key (name, value, label) for this particular component

第一个是name属性,用于解析OGNL表达式以将值设置为值堆栈.只要您没有这样的值,就会抛出OGNL异常,但是参数拦截器用于捕获和忽略这种异常.而且只有打开devMode,您才能在日志中看到此异常.

The first is a name attribute is used to parse for OGNL expression to set a value to the value stack. As far as you don't have such value the OGNL exception is thrown, but parameters interceptor used to catch and ignore this kind of exceptions. And only if you have devMode is turned on you can see this exception in the logs.

通常,如果在Struts标记中使用key属性,则应使用相同的属性名称作为属性文件中的键,以便正确绑定action属性.

Usually if you are using a key attribute in the Struts tag you should use the same property name as a key in the properties file, so it correctly bind the action property.

这篇关于Struts2 devMode使用“键"时异常提交标签中的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆