You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Dhananjay Makwana <ma...@semandex.net> on 2013/03/19 11:02:40 UTC
Struts2: Problem with form fields
Hi Everyone,
I am new to Struts2. I am creating a basic page where user can see login credentials for few
accounts (any type like Email, FB etc.) and if one of them is not present then add them. Each
account has a list of properties with a name and a string value (keeping it simple).
Now in my S2 application, I have an AccountList action which gets all accounts and puts them in my
user session. If an account is not added then it has a skeleton flag set. If this flag is set then I
want to set properties of that account and add it to the system. I have created AddAccountAction for
that.
Here's how my accountList.jsp looks like.
<div class="accountList">
<h4>Account AAA</h4>
<s:set name="acct" value="#session.accounts.get('aaa')" />
<div class="one half account padded">
<ul>
<s:iterator value="#acct.properties">
<li>
<s:property value="name" />: <s:property value="value" default="[not_set]" />
</li>
</s:iterator>
</ul>
<s:form id="change_aaa_form" namespace="settings" action="addAccount"
style="display:none;">
<s:hidden name="acctId" value="aaa" />
<s:textfield label="%{'user.token'}"
name="#session.accounts['aaa'].properties[0].value" ></s:textfield>
<s:textfield label="%{'user.secret'}"
name="#session.accounts['aaa'].properties[1].value" ></s:textfield>
<s:submit key="Submit" />
</s:form>
</div>
My, AccountList action method looks like this
@Override
public String execute() throws Exception {
Map<String, Account> accts = AccountUtils.getInstance( getStore() ).getAccounts();
getSession().put( "accounts", accts );
return SUCCESS;
}
My Account class is a simple bean with a list of AccountProperty beans (with setters and getters).
Account.java
private String id;
private String name;
private List<AccountProperty> properties;
private boolean isSkeleton;
AccountProperty.java
private String name;
private String value;
private boolean isPassword;
The AddAccountAction looks like this.
public String execute() {
@SuppressWarnings("unchecked")
Map<String, Account> accts = (Map<String, Account>) getSession().get( "accounts" );
Account a = accts.get( getAcctId() );
if ( a == null )
return ERROR;
for ( AccountProperty p : a.getProperties()) {
System.out.println( p );
}
return SUCCESS;
}
My problem is that I cannot get the form to store the properties in my AddAccountAction. I keep
getting following warning on console.
2013-03-19 14:33:25,683 [http-8080-2] WARN com.opensymphony.xwork2.interceptor.ParametersInterceptor
- Parameter [#session.accounts['aaa'].properties[0].value] didn't match acceptedPattern pattern!
2013-03-19 14:33:25,704 [http-8080-2] ERROR
com.opensymphony.xwork2.interceptor.ParametersInterceptor - Developer Notification (set
struts.devMode to false to disable this message):
Unexpected Exception caught setting 'Submit' on 'class net.semandex.salsa.web.prm.AddAccountAction:
Error setting expression 'Submit' with value ['Submit', ]
I searched for this problem. I read [1] and [2] but somehow it is not working for me. I have also
tried to create an empty Account with empty property list in my AddAcountAction class and tried
<s:textfield name="account.properties[0].value"
But I get the same error as above. I really want to keep my Account and AccountProperty classes
generic like this. Most of the S2 examples that I saw are talking about using specific property
names like "person.name" with associated methods like getPerson().getName()
[1]: http://stackoverflow.com/questions/8705413/struts2-dynamic-form-fields-and-database-data-retrieval
[2]: http://stackoverflow.com/questions/5834944/populate-liststring-in-struts2-from-form-data
Thanks in advance,
-DJ
Re: Struts2: Problem with form fields
Posted by Dhananjay Makwana <ma...@semandex.net>.
Thanks for solution. I followed [2] and it works perfectly. Now any suggestions/patterns for
implementations of "acceptableParameterName(String)" method, apart from the obvious checking of
parameter startWith, endsWith etc.?
On 3/19/13 5:41 PM, Lukasz Lenart wrote:
> 2013/3/19 Dhananjay Makwana <ma...@semandex.net>:
>> I do have an excludePattern but that is for my css, js files. Here's my
>> struts.xml file. I am using version 2.3.8.
> I have double checked and your problem is related to acceptParamNames
> property of ParametersInterceptor which was defined very restrictive
> [1] to secure framework and applications. You can either relax the
> pattern (not recommended) or implement
> ParameterNameAware#acceptableParameterName(String) to accept param
> names by action [2].
>
> [1] http://struts.apache.org/development/2.x/docs/s2-009.html
> [2] http://struts.apache.org/development/2.x/docs/parameters-interceptor.html#ParametersInterceptor-Excludingparameters
>
>
> Regards
Re: Struts2: Problem with form fields
Posted by Lukasz Lenart <lu...@apache.org>.
2013/3/19 Dhananjay Makwana <ma...@semandex.net>:
> I do have an excludePattern but that is for my css, js files. Here's my
> struts.xml file. I am using version 2.3.8.
I have double checked and your problem is related to acceptParamNames
property of ParametersInterceptor which was defined very restrictive
[1] to secure framework and applications. You can either relax the
pattern (not recommended) or implement
ParameterNameAware#acceptableParameterName(String) to accept param
names by action [2].
[1] http://struts.apache.org/development/2.x/docs/s2-009.html
[2] http://struts.apache.org/development/2.x/docs/parameters-interceptor.html#ParametersInterceptor-Excludingparameters
Regards
--
Łukasz
+ 48 606 323 122 http://www.lenart.org.pl/
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Struts2: Problem with form fields
Posted by Dhananjay Makwana <ma...@semandex.net>.
I do have an excludePattern but that is for my css, js files. Here's my struts.xml file. I am using
version 2.3.8.
<struts>
<constant name="struts.devMode" value="true" />
<constant name="struts.action.extension" value=""/>
<!-- comma separated list of regexp url pattern -->
<constant name="struts.action.excludePattern" value="/css/.*?, /groundwork/.*?, /js/.*?" />
<package name="settings" namespace="/settings" extends="tiles-default">
<action name="accounts" class="prm.AccountList">
<result name="success" type="tiles">/accountList.tiles</result>
</action>
<action name="addAccount" class="prm.AddAccountAction">
<result name="success" type="redirectAction">
<param name="actionName">accounts</param>
</result>
</action>
</package>
</struts>
On 3/19/13 4:22 PM, Lukasz Lenart wrote:
> 2013/3/19 Dhananjay Makwana <ma...@semandex.net>:
>> 2013-03-19 14:33:25,683 [http-8080-2] WARN
>> com.opensymphony.xwork2.interceptor.ParametersInterceptor - Parameter
>> [#session.accounts['aaa'].properties[0].value] didn't match acceptedPattern
>> pattern!
> This is odd, as I have already checked and
> #session.accounts['aaa'].properties[0].value matches the default
> acceptedPattern provided with ParametersInterceptor. Did you change
> that?
>
> struts.xml? version?
>
>
> Regards
Re: Struts2: Problem with form fields
Posted by Lukasz Lenart <lu...@apache.org>.
2013/3/19 Dhananjay Makwana <ma...@semandex.net>:
> 2013-03-19 14:33:25,683 [http-8080-2] WARN
> com.opensymphony.xwork2.interceptor.ParametersInterceptor - Parameter
> [#session.accounts['aaa'].properties[0].value] didn't match acceptedPattern
> pattern!
This is odd, as I have already checked and
#session.accounts['aaa'].properties[0].value matches the default
acceptedPattern provided with ParametersInterceptor. Did you change
that?
struts.xml? version?
Regards
--
Łukasz
+ 48 606 323 122 http://www.lenart.org.pl/
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org