labelizing submit buttons

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

labelizing submit buttons

webmeiker
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!


--
Reply | Threaded
Open this post in threaded view
|

Re: labelizing submit buttons

Maurizio Cucchiara
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 <[hidden email]>:

> 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: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: labelizing submit buttons

M. Rakowski

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: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: labelizing submit buttons

webmeiker
It doesn’t work…

Neither putting ‘btn.search=Search’ in: my-global-messages.properties,
package.properties, my-action.properties



¿?¿?


2010/11/29 M. Rakowski <[hidden email]>

>
> 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: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>


--
Reply | Threaded
Open this post in threaded view
|

Re: labelizing submit buttons

webmeiker
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 <[hidden email]>

> It doesn’t work…
>
> Neither putting ‘btn.search=Search’ in: my-global-messages.properties,
> package.properties, my-action.properties
>
>
>
> ¿?¿?
>
>
> 2010/11/29 M. Rakowski <[hidden email]>
>
>
>> 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: [hidden email]
>> For additional commands, e-mail: [hidden email]
>>
>>
>
>
> --
>
>
>


--
Reply | Threaded
Open this post in threaded view
|

Re: labelizing submit buttons

Li Ying
In reply to this post by webmeiker
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: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: labelizing submit buttons

M. Rakowski
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: [hidden email]
For additional commands, e-mail: [hidden email]