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

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

问题描述

我使用 Struts2 并打开了 devMode 以捕获尽可能多的警告和错误.现在我遇到了一些只在 devMode 中通知的 SEVERE 通知.

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 属性以从名为 <的属性中获取按钮文本 "Entrar"代码>global.BOTON_LOGIN.该按钮是调用映射到类 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>

SEVERE 通知消失了.

and the SEVERE notification is gone.

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

Is there something I do wrong in the first case?

推荐答案

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

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 属性,您应该使用与属性文件中的键相同的属性名称,以便正确绑定操作属性.

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 使用“key"时出现异常提交标签中的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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