struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Li Ying <liying.cn.2...@gmail.com>
Subject Re: labelizing submit buttons
Date Tue, 30 Nov 2010 13:50:20 GMT
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


Mime
View raw message