You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by webmeiker <in...@webmeiker.com> on 2010/11/29 12:45:02 UTC
labelizing submit buttons
Hi all,
Could somebody help me with the next issue?
In a submit button I want to use a customized label (which is extracted from
a .properties file).
The problem is that I get the next exception:
Error setting expression 'btn.search' with value
'[Ljava.lang.String;@1ed56e2'
*ognl.OgnlException*: target is null for setProperty(null, "search",
[Ljava.lang.String;@1ed56e2)
at ognl.OgnlRuntime.setProperty(*OgnlRuntime.java:1651*)
Here is the code involved:
…in the .properties:
btn.search=Search
…in the .jsp:
<s:submit key="btn.search " />
Does somebody know how to avoid this exception without implementing a method
‘setSearch()’ in the action?
Thanks in advance!
--
Re: labelizing submit buttons
Posted by "M. Rakowski" <ma...@rakowski.biz>.
maybe it is a little late, but here is a "legal" way
to put a label on s:submit:
<s:submit value="%{getText('btn.search')}" />
With btn.search defined in .properties file.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: labelizing submit buttons
Posted by Li Ying <li...@gmail.com>.
I think your tag has a leak of attribute "method"
Your code:
<s:submit key="btn.search" />
will generate HTML likes:
<input type="submit" name="btn.search" value="Search"/>
When you click this button, there will be a http request parameter
like "btn.search=Search".
Struts2 will accept this parameter, and try to save it to your action property.
So, there will be a property setting, which cause method invoking likes:
YourAction.getBtn().setSearch("Search")
But your action does not have a property named "btn",
so getBtn() will get a null, and of cause the setSearch part will fail.
If you add a "method" attribute to submit tag, like:
<s:submit key="btn.search" method="search" />
It will generate HTML like:
<input type="submit" value="Search" name="method:search" />
Notice, the "name" is now "method:search"
So, when you click this button, the http request will be:
"method:search=Search".
Struts will recognize the prefix "method:", so it know that this is a
flag to specify which method to execute, but not a input data which
need to be set in to property of Action.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: labelizing submit buttons
Posted by webmeiker <in...@webmeiker.com>.
There is an easy trick:
Define all your buttons in your global.properties starting with word ‘*dojo*’
like this:
dojo.btn.eliminar=Borrar
dojo.btn.editar=Editar
dojo.btn.inscripcion=Inscribirse
dojo.btn.buscar=Buscar
That way you avoid ParametersInterceptor to search for unimplemented setters
as a result of the excludeParams configuration parameter:
<interceptor-ref name="params">
<param name="excludeParams">dojo\..*,^struts\..*</param>
</interceptor-ref>
Hope this helps!
2010/11/30 webmeiker <in...@webmeiker.com>
> It doesn’t work…
>
> Neither putting ‘btn.search=Search’ in: my-global-messages.properties,
> package.properties, my-action.properties
>
>
>
> ¿?¿?
>
>
> 2010/11/29 M. Rakowski <ma...@rakowski.biz>
>
>
>> i have exactly the same problem:
>>
>> <s:text name="event.name"/>
>>
>> with event.name set in the package.properties file: works ok.
>>
>> <s:submit key="button.create">
>>
>> with button.create set in the same .properties-file
>> causes exception.
>>
>> Suggestion:
>> It works only if you use ActionClassName.properties file
>> instead of package.properties?
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>
>
> --
>
>
>
--
Re: labelizing submit buttons
Posted by webmeiker <in...@webmeiker.com>.
It doesn’t work…
Neither putting ‘btn.search=Search’ in: my-global-messages.properties,
package.properties, my-action.properties
¿?¿?
2010/11/29 M. Rakowski <ma...@rakowski.biz>
>
> i have exactly the same problem:
>
> <s:text name="event.name"/>
>
> with event.name set in the package.properties file: works ok.
>
> <s:submit key="button.create">
>
> with button.create set in the same .properties-file
> causes exception.
>
> Suggestion:
> It works only if you use ActionClassName.properties file
> instead of package.properties?
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
--
Re: labelizing submit buttons
Posted by "M. Rakowski" <ma...@rakowski.biz>.
i have exactly the same problem:
<s:text name="event.name"/>
with event.name set in the package.properties file: works ok.
<s:submit key="button.create">
with button.create set in the same .properties-file
causes exception.
Suggestion:
It works only if you use ActionClassName.properties file
instead of package.properties?
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: labelizing submit buttons
Posted by Maurizio Cucchiara <ma...@gmail.com>.
You shouldn't need a setSearch method inside your action:
the bEst way to make it work is to verify that your
ActionClassName.properties contains a btn.search entry.
2010/11/29 webmeiker <in...@webmeiker.com>:
> Hi all,
>
> Could somebody help me with the next issue?
>
>
>
> In a submit button I want to use a customized label (which is extracted from
> a .properties file).
>
> The problem is that I get the next exception:
>
>
>
> Error setting expression 'btn.search' with value
> '[Ljava.lang.String;@1ed56e2'
>
> *ognl.OgnlException*: target is null for setProperty(null, "search",
> [Ljava.lang.String;@1ed56e2)
>
> at ognl.OgnlRuntime.setProperty(*OgnlRuntime.java:1651*)
>
>
>
> Here is the code involved:
>
>
>
> …in the .properties:
>
> btn.search=Search
>
>
>
> …in the .jsp:
>
> <s:submit key="btn.search " />
>
>
>
> Does somebody know how to avoid this exception without implementing a method
> ‘setSearch()’ in the action?
>
>
>
> Thanks in advance!
>
>
> --
>
--
Maurizio Cucchiara
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org