You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by ch...@chrismiles.org on 2008/07/07 17:38:30 UTC
Getting Struts2 Parameters?
In my struts.xml I have set up a stack for "defaultStack" to include the
Parameters Interceptor, and I have then set the default stack to
"defaultStack".
In my action class I have set up a setter injector called
setProductId(String productId) which sets to a local variable.
I then have a form which points to that action, which is AddToCart.action
to be precise. I have an hideen HTML input with the name "productId" and a
value set, however when I submit the form the productId variable in the
action class has not been set?
Is there something obvious that I might be missing?
Many thanks and best regards,
Chris
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Getting Struts2 Parameters?
Posted by Jim Kiley <jh...@summa-tech.com>.
Happens to the best of us. :-)
On Tue, Jul 8, 2008 at 5:38 PM, Chris Miles <ch...@chrismiles.org> wrote:
> Argh, You know I could not see that at all?
>
> Thank you :)
>
> Chris
> ----- Original Message ----- From: "Jim Kiley" <jh...@summa-tech.com>
> To: "Struts Users Mailing List" <us...@struts.apache.org>
> Sent: Monday, July 07, 2008 10:52 PM
> Subject: Re: Getting Struts2 Parameters?
>
>
> Your setter is private. It needs to be public.
>>
>> On Mon, Jul 7, 2008 at 5:49 PM, Chris Miles <ch...@chrismiles.org> wrote:
>>
>> No exceptions.
>>>
>>> The action class is as follows.
>>>
>>> public class AddToCartAction extends ActionSupport implements Action {
>>> private String productId = "";
>>> private int quantity = 0;
>>>
>>> private void setProductId(String productId) {
>>> this.productId = productId;
>>> }
>>>
>>> private void setQuantity(int quantity) {
>>> this.quantity = quantity;
>>> }
>>>
>>> public String execute() {
>>> System.out.println("Product Id = " + productId);
>>> System.out.println("Quantity = " + quantity);
>>> return Action.SUCCESS;
>>> }
>>> }
>>>
>>> My struts.xml is
>>>
>>> <?xml version="1.0" encoding="UTF-8" ?>
>>> <!DOCTYPE struts PUBLIC
>>> "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
>>> "http://struts.apache.org/dtds/struts-2.0.dtd">
>>>
>>> <struts>
>>> <package name="default" extends="struts-default" namespace="/checkout">
>>> <interceptors>
>>>
>>> <interceptor name="static-params"
>>> class="com.opensymphony.xwork2.interceptor.StaticParametersInterceptor"
>>> />
>>> <interceptor name="params"
>>> class="com.opensymphony.xwork2.interceptor.ParametersInterceptor" />
>>>
>>> <interceptor-stack name="defaultStack">
>>> <interceptor-ref name="static-params" />
>>> <interceptor-ref name="params" />
>>> </interceptor-stack>
>>>
>>> </interceptors>
>>>
>>> <default-interceptor-ref name="defaultStack"/>
>>>
>>> <!-- Product Form / addToCart -->
>>> <action name="viewCart"
>>> class="cakeinabox.struts2.actions.AddToCartAction">
>>> <result name="success">/jsp/checkout/viewCart.jsp</result>
>>> <result name="error">/jsp/checkout/error.jsp</result>
>>> </action>
>>> </package>
>>> </struts>
>>>
>>> and my JSP is:
>>>
>>> <form action="/checkout/addToCart.action" method="GET">
>>> <input type="hidden" value="<%=pId%>" name="productId">
>>> <input type="hidden" value="1" name="quantity">
>>> ..............
>>>
>>> pId renders as a valid productId in the HTML - this has been checked.
>>>
>>> I have also tried a POST rather than a GET with no joy.
>>>
>>> many thanks
>>>
>>> Chrix
>>> ----- Original Message ----- From: "Musachy Barroso" <mu...@gmail.com>
>>> To: "Struts Users Mailing List" <us...@struts.apache.org>
>>> Sent: Monday, July 07, 2008 4:46 PM
>>> Subject: Re: Getting Struts2 Parameters?
>>>
>>>
>>> Are there any exceptions in the logs? Does your class implement
>>>
>>>> ModelDriven? if you posts the relevant parts of your configuration
>>>> (jsp fragment, action and xml fragment), it will be easier to get
>>>> help.
>>>>
>>>> musachy
>>>>
>>>> On Mon, Jul 7, 2008 at 11:38 AM, <ch...@chrismiles.org> wrote:
>>>>
>>>> In my struts.xml I have set up a stack for "defaultStack" to include
>>>>> the
>>>>> Parameters Interceptor, and I have then set the default stack to
>>>>> "defaultStack".
>>>>>
>>>>> In my action class I have set up a setter injector called
>>>>> setProductId(String productId) which sets to a local variable.
>>>>>
>>>>> I then have a form which points to that action, which is
>>>>> AddToCart.action
>>>>> to be precise. I have an hideen HTML input with the name "productId"
>>>>> and
>>>>> a
>>>>> value set, however when I submit the form the productId variable in the
>>>>> action class has not been set?
>>>>>
>>>>> Is there something obvious that I might be missing?
>>>>>
>>>>> Many thanks and best regards,
>>>>>
>>>>> Chris
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>>>> For additional commands, e-mail: user-help@struts.apache.org
>>>>>
>>>>>
>>>>>
>>>>>
>>>>
>>>> --
>>>> "Hey you! Would you help me to carry the stone?" Pink Floyd
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>>> For additional commands, e-mail: user-help@struts.apache.org
>>>>
>>>>
>>>>
>>>> --
>>>> Internal Virus Database is out-of-date.
>>>> Checked by AVG Free Edition.
>>>> Version: 7.5.446 / Virus Database: 268.18.12/724 - Release Date:
>>>> 16/03/2007 12:12
>>>>
>>>>
>>>>
>>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>> For additional commands, e-mail: user-help@struts.apache.org
>>>
>>>
>>>
>>
>> --
>> Jim Kiley
>> Technical Consultant | Summa
>> [p] 412.258.3346 [m] 412.445.1729
>> http://www.summa-tech.com
>>
>>
>
>
> --------------------------------------------------------------------------------
>
>
> Internal Virus Database is out-of-date.
> Checked by AVG Free Edition.
> Version: 7.5.446 / Virus Database: 268.18.12/724 - Release Date: 16/03/2007
> 12:12
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
--
Jim Kiley
Technical Consultant | Summa
[p] 412.258.3346 [m] 412.445.1729
http://www.summa-tech.com
Re: Getting Struts2 Parameters?
Posted by Chris Miles <ch...@chrismiles.org>.
Argh, You know I could not see that at all?
Thank you :)
Chris
----- Original Message -----
From: "Jim Kiley" <jh...@summa-tech.com>
To: "Struts Users Mailing List" <us...@struts.apache.org>
Sent: Monday, July 07, 2008 10:52 PM
Subject: Re: Getting Struts2 Parameters?
> Your setter is private. It needs to be public.
>
> On Mon, Jul 7, 2008 at 5:49 PM, Chris Miles <ch...@chrismiles.org> wrote:
>
>> No exceptions.
>>
>> The action class is as follows.
>>
>> public class AddToCartAction extends ActionSupport implements Action {
>> private String productId = "";
>> private int quantity = 0;
>>
>> private void setProductId(String productId) {
>> this.productId = productId;
>> }
>>
>> private void setQuantity(int quantity) {
>> this.quantity = quantity;
>> }
>>
>> public String execute() {
>> System.out.println("Product Id = " + productId);
>> System.out.println("Quantity = " + quantity);
>> return Action.SUCCESS;
>> }
>> }
>>
>> My struts.xml is
>>
>> <?xml version="1.0" encoding="UTF-8" ?>
>> <!DOCTYPE struts PUBLIC
>> "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
>> "http://struts.apache.org/dtds/struts-2.0.dtd">
>>
>> <struts>
>> <package name="default" extends="struts-default" namespace="/checkout">
>> <interceptors>
>>
>> <interceptor name="static-params"
>> class="com.opensymphony.xwork2.interceptor.StaticParametersInterceptor"
>> />
>> <interceptor name="params"
>> class="com.opensymphony.xwork2.interceptor.ParametersInterceptor" />
>>
>> <interceptor-stack name="defaultStack">
>> <interceptor-ref name="static-params" />
>> <interceptor-ref name="params" />
>> </interceptor-stack>
>>
>> </interceptors>
>>
>> <default-interceptor-ref name="defaultStack"/>
>>
>> <!-- Product Form / addToCart -->
>> <action name="viewCart"
>> class="cakeinabox.struts2.actions.AddToCartAction">
>> <result name="success">/jsp/checkout/viewCart.jsp</result>
>> <result name="error">/jsp/checkout/error.jsp</result>
>> </action>
>> </package>
>> </struts>
>>
>> and my JSP is:
>>
>> <form action="/checkout/addToCart.action" method="GET">
>> <input type="hidden" value="<%=pId%>" name="productId">
>> <input type="hidden" value="1" name="quantity">
>> ..............
>>
>> pId renders as a valid productId in the HTML - this has been checked.
>>
>> I have also tried a POST rather than a GET with no joy.
>>
>> many thanks
>>
>> Chrix
>> ----- Original Message ----- From: "Musachy Barroso" <mu...@gmail.com>
>> To: "Struts Users Mailing List" <us...@struts.apache.org>
>> Sent: Monday, July 07, 2008 4:46 PM
>> Subject: Re: Getting Struts2 Parameters?
>>
>>
>> Are there any exceptions in the logs? Does your class implement
>>> ModelDriven? if you posts the relevant parts of your configuration
>>> (jsp fragment, action and xml fragment), it will be easier to get
>>> help.
>>>
>>> musachy
>>>
>>> On Mon, Jul 7, 2008 at 11:38 AM, <ch...@chrismiles.org> wrote:
>>>
>>>> In my struts.xml I have set up a stack for "defaultStack" to include
>>>> the
>>>> Parameters Interceptor, and I have then set the default stack to
>>>> "defaultStack".
>>>>
>>>> In my action class I have set up a setter injector called
>>>> setProductId(String productId) which sets to a local variable.
>>>>
>>>> I then have a form which points to that action, which is
>>>> AddToCart.action
>>>> to be precise. I have an hideen HTML input with the name "productId"
>>>> and
>>>> a
>>>> value set, however when I submit the form the productId variable in the
>>>> action class has not been set?
>>>>
>>>> Is there something obvious that I might be missing?
>>>>
>>>> Many thanks and best regards,
>>>>
>>>> Chris
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>>> For additional commands, e-mail: user-help@struts.apache.org
>>>>
>>>>
>>>>
>>>
>>>
>>> --
>>> "Hey you! Would you help me to carry the stone?" Pink Floyd
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>> For additional commands, e-mail: user-help@struts.apache.org
>>>
>>>
>>>
>>> --
>>> Internal Virus Database is out-of-date.
>>> Checked by AVG Free Edition.
>>> Version: 7.5.446 / Virus Database: 268.18.12/724 - Release Date:
>>> 16/03/2007 12:12
>>>
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>
>
> --
> Jim Kiley
> Technical Consultant | Summa
> [p] 412.258.3346 [m] 412.445.1729
> http://www.summa-tech.com
>
--------------------------------------------------------------------------------
Internal Virus Database is out-of-date.
Checked by AVG Free Edition.
Version: 7.5.446 / Virus Database: 268.18.12/724 - Release Date: 16/03/2007
12:12
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Getting Struts2 Parameters?
Posted by Jim Kiley <jh...@summa-tech.com>.
Your setter is private. It needs to be public.
On Mon, Jul 7, 2008 at 5:49 PM, Chris Miles <ch...@chrismiles.org> wrote:
> No exceptions.
>
> The action class is as follows.
>
> public class AddToCartAction extends ActionSupport implements Action {
> private String productId = "";
> private int quantity = 0;
>
> private void setProductId(String productId) {
> this.productId = productId;
> }
>
> private void setQuantity(int quantity) {
> this.quantity = quantity;
> }
>
> public String execute() {
> System.out.println("Product Id = " + productId);
> System.out.println("Quantity = " + quantity);
> return Action.SUCCESS;
> }
> }
>
> My struts.xml is
>
> <?xml version="1.0" encoding="UTF-8" ?>
> <!DOCTYPE struts PUBLIC
> "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
> "http://struts.apache.org/dtds/struts-2.0.dtd">
>
> <struts>
> <package name="default" extends="struts-default" namespace="/checkout">
> <interceptors>
>
> <interceptor name="static-params"
> class="com.opensymphony.xwork2.interceptor.StaticParametersInterceptor" />
> <interceptor name="params"
> class="com.opensymphony.xwork2.interceptor.ParametersInterceptor" />
>
> <interceptor-stack name="defaultStack">
> <interceptor-ref name="static-params" />
> <interceptor-ref name="params" />
> </interceptor-stack>
>
> </interceptors>
>
> <default-interceptor-ref name="defaultStack"/>
>
> <!-- Product Form / addToCart -->
> <action name="viewCart"
> class="cakeinabox.struts2.actions.AddToCartAction">
> <result name="success">/jsp/checkout/viewCart.jsp</result>
> <result name="error">/jsp/checkout/error.jsp</result>
> </action>
> </package>
> </struts>
>
> and my JSP is:
>
> <form action="/checkout/addToCart.action" method="GET">
> <input type="hidden" value="<%=pId%>" name="productId">
> <input type="hidden" value="1" name="quantity">
> ..............
>
> pId renders as a valid productId in the HTML - this has been checked.
>
> I have also tried a POST rather than a GET with no joy.
>
> many thanks
>
> Chrix
> ----- Original Message ----- From: "Musachy Barroso" <mu...@gmail.com>
> To: "Struts Users Mailing List" <us...@struts.apache.org>
> Sent: Monday, July 07, 2008 4:46 PM
> Subject: Re: Getting Struts2 Parameters?
>
>
> Are there any exceptions in the logs? Does your class implement
>> ModelDriven? if you posts the relevant parts of your configuration
>> (jsp fragment, action and xml fragment), it will be easier to get
>> help.
>>
>> musachy
>>
>> On Mon, Jul 7, 2008 at 11:38 AM, <ch...@chrismiles.org> wrote:
>>
>>> In my struts.xml I have set up a stack for "defaultStack" to include the
>>> Parameters Interceptor, and I have then set the default stack to
>>> "defaultStack".
>>>
>>> In my action class I have set up a setter injector called
>>> setProductId(String productId) which sets to a local variable.
>>>
>>> I then have a form which points to that action, which is AddToCart.action
>>> to be precise. I have an hideen HTML input with the name "productId" and
>>> a
>>> value set, however when I submit the form the productId variable in the
>>> action class has not been set?
>>>
>>> Is there something obvious that I might be missing?
>>>
>>> Many thanks and best regards,
>>>
>>> Chris
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>> For additional commands, e-mail: user-help@struts.apache.org
>>>
>>>
>>>
>>
>>
>> --
>> "Hey you! Would you help me to carry the stone?" Pink Floyd
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>>
>> --
>> Internal Virus Database is out-of-date.
>> Checked by AVG Free Edition.
>> Version: 7.5.446 / Virus Database: 268.18.12/724 - Release Date:
>> 16/03/2007 12:12
>>
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
--
Jim Kiley
Technical Consultant | Summa
[p] 412.258.3346 [m] 412.445.1729
http://www.summa-tech.com
Re: Getting Struts2 Parameters?
Posted by Chris Miles <ch...@chrismiles.org>.
No exceptions.
The action class is as follows.
public class AddToCartAction extends ActionSupport implements Action {
private String productId = "";
private int quantity = 0;
private void setProductId(String productId) {
this.productId = productId;
}
private void setQuantity(int quantity) {
this.quantity = quantity;
}
public String execute() {
System.out.println("Product Id = " + productId);
System.out.println("Quantity = " + quantity);
return Action.SUCCESS;
}
}
My struts.xml is
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="default" extends="struts-default" namespace="/checkout">
<interceptors>
<interceptor name="static-params"
class="com.opensymphony.xwork2.interceptor.StaticParametersInterceptor" />
<interceptor name="params"
class="com.opensymphony.xwork2.interceptor.ParametersInterceptor" />
<interceptor-stack name="defaultStack">
<interceptor-ref name="static-params" />
<interceptor-ref name="params" />
</interceptor-stack>
</interceptors>
<default-interceptor-ref name="defaultStack"/>
<!-- Product Form / addToCart -->
<action name="viewCart"
class="cakeinabox.struts2.actions.AddToCartAction">
<result name="success">/jsp/checkout/viewCart.jsp</result>
<result name="error">/jsp/checkout/error.jsp</result>
</action>
</package>
</struts>
and my JSP is:
<form action="/checkout/addToCart.action" method="GET">
<input type="hidden" value="<%=pId%>" name="productId">
<input type="hidden" value="1" name="quantity">
..............
pId renders as a valid productId in the HTML - this has been checked.
I have also tried a POST rather than a GET with no joy.
many thanks
Chrix
----- Original Message -----
From: "Musachy Barroso" <mu...@gmail.com>
To: "Struts Users Mailing List" <us...@struts.apache.org>
Sent: Monday, July 07, 2008 4:46 PM
Subject: Re: Getting Struts2 Parameters?
> Are there any exceptions in the logs? Does your class implement
> ModelDriven? if you posts the relevant parts of your configuration
> (jsp fragment, action and xml fragment), it will be easier to get
> help.
>
> musachy
>
> On Mon, Jul 7, 2008 at 11:38 AM, <ch...@chrismiles.org> wrote:
>> In my struts.xml I have set up a stack for "defaultStack" to include the
>> Parameters Interceptor, and I have then set the default stack to
>> "defaultStack".
>>
>> In my action class I have set up a setter injector called
>> setProductId(String productId) which sets to a local variable.
>>
>> I then have a form which points to that action, which is AddToCart.action
>> to be precise. I have an hideen HTML input with the name "productId" and
>> a
>> value set, however when I submit the form the productId variable in the
>> action class has not been set?
>>
>> Is there something obvious that I might be missing?
>>
>> Many thanks and best regards,
>>
>> Chris
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>
>
>
> --
> "Hey you! Would you help me to carry the stone?" Pink Floyd
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
>
> --
> Internal Virus Database is out-of-date.
> Checked by AVG Free Edition.
> Version: 7.5.446 / Virus Database: 268.18.12/724 - Release Date:
> 16/03/2007 12:12
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Getting Struts2 Parameters?
Posted by Musachy Barroso <mu...@gmail.com>.
Are there any exceptions in the logs? Does your class implement
ModelDriven? if you posts the relevant parts of your configuration
(jsp fragment, action and xml fragment), it will be easier to get
help.
musachy
On Mon, Jul 7, 2008 at 11:38 AM, <ch...@chrismiles.org> wrote:
> In my struts.xml I have set up a stack for "defaultStack" to include the
> Parameters Interceptor, and I have then set the default stack to
> "defaultStack".
>
> In my action class I have set up a setter injector called
> setProductId(String productId) which sets to a local variable.
>
> I then have a form which points to that action, which is AddToCart.action
> to be precise. I have an hideen HTML input with the name "productId" and a
> value set, however when I submit the form the productId variable in the
> action class has not been set?
>
> Is there something obvious that I might be missing?
>
> Many thanks and best regards,
>
> Chris
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
--
"Hey you! Would you help me to carry the stone?" Pink Floyd
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org