Reputation: 105
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.
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', ]
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>
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" />
which in turn generates that HTML code:
<button type="submit" id="login_0" value="Entrar">Entrar</button>
and the SEVERE notification is gone.
Is there something I do wrong in the first case?
Upvotes: 1
Views: 701
Reputation: 1
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
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.
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.
Upvotes: 1