You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Ray Clough <ra...@allthisisthat.com> on 2007/05/09 20:30:40 UTC

(S2) submit question

I have an action with a wildcard mapping:

		<action name="Settings_*" method="{1}"
				class="com.kamakura.struts2.action.SettingsAction" 
				 >
			<result>/jspx/settings.jspx </result>
		</action>

The jsp page has 2 links which submit the form using javascript.  Here is
one of the functions:

			function save() {
				alert('kowabunga, dude.');
				document.settingsForm.action = 'Settings_save.action';
				document.settingsForm.submit();
			}

This does in fact submit to the correct action class methods.  The problem
is that the action class instance is not the same between one submission and
the next.  That is, the 'init()' method in the action class sets some
instance variables.  The "save" method does not have access to those
instance variables, because a new instance of the was created (a different
instance 'id').  Is the creation of a new instance the standard behavior - I
can't believe it is, because that would make the whole 'thread-safe' model
in S2 pointless.  Am I doing something silly or wrong (I could believe
either)?

Thanks,
Ray Clough


-- 
View this message in context: http://www.nabble.com/%28S2%29-submit-question-tf3717366.html#a10399618
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: (S2) submit question

Posted by Laurie Harper <la...@holoweb.net>.
Ray Clough wrote:
> I'm obviously missing something.   Am I understanding this scenario
> correctly:
> 
> I have 2 methods in my Action class:  'init' and 'save'.  The 'init' method
> instantiates an instance variable 'myList', which is available to the jsp
> page thru a 'getList' method.  The page is loaded and the 'myList'
> properties are displayed and edited.  The user presses the 'save' button,
> and a new instance of the Action is class is created, so there is no longer
> a reference to the edited 'myList' object.

Correct. Actions are instantiated per-request, so if you need that 
object to be available in the save() method, you'll need to 
fetch/construct it again.

> If I were to implement 'ModelDriven' to push the 'myList' onto the stack,
> would this object persist through the Request/Response cycle.  Would there
> be any benefit to that over storing it in the session?

No, it wouldn't. The OGNL value stack is built per-request too. You will 
either have to put the list into the session or, as noted above, 
re-fetch or re-build it during request processing for the save() method.

L.

> Thanks,
> Ray Clough
> 
> 
> Dave Newton-4 wrote:
>> --- Ray Clough <ra...@allthisisthat.com> wrote:
>>> Is the creation of a new instance the standard 
>>> behavior - I can't believe it is, because that would
>>> make the whole 'thread-safe' model in S2 pointless.
>> That's *why* it's thread-safe.
>>
>> d.
>>
>>
>>
>>  
>> ____________________________________________________________________________________
>> No need to miss a message. Get email on-the-go 
>> with Yahoo! Mail for Mobile. Get started.
>> http://mobile.yahoo.com/mail 
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>>
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: (S2) submit question

Posted by Ray Clough <ra...@allthisisthat.com>.
I'm obviously missing something.   Am I understanding this scenario
correctly:

I have 2 methods in my Action class:  'init' and 'save'.  The 'init' method
instantiates an instance variable 'myList', which is available to the jsp
page thru a 'getList' method.  The page is loaded and the 'myList'
properties are displayed and edited.  The user presses the 'save' button,
and a new instance of the Action is class is created, so there is no longer
a reference to the edited 'myList' object.

If I were to implement 'ModelDriven' to push the 'myList' onto the stack,
would this object persist through the Request/Response cycle.  Would there
be any benefit to that over storing it in the session?

Thanks,
Ray Clough


Dave Newton-4 wrote:
> 
> --- Ray Clough <ra...@allthisisthat.com> wrote:
>> Is the creation of a new instance the standard 
>> behavior - I can't believe it is, because that would
> 
>> make the whole 'thread-safe' model in S2 pointless.
> 
> That's *why* it's thread-safe.
> 
> d.
> 
> 
> 
>  
> ____________________________________________________________________________________
> No need to miss a message. Get email on-the-go 
> with Yahoo! Mail for Mobile. Get started.
> http://mobile.yahoo.com/mail 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/%28S2%29-submit-question-tf3717366.html#a10403062
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: (S2) submit question

Posted by Dave Newton <ne...@yahoo.com>.
--- Ray Clough <ra...@allthisisthat.com> wrote:
> Is the creation of a new instance the standard 
> behavior - I can't believe it is, because that would

> make the whole 'thread-safe' model in S2 pointless.

That's *why* it's thread-safe.

d.



 
____________________________________________________________________________________
No need to miss a message. Get email on-the-go 
with Yahoo! Mail for Mobile. Get started.
http://mobile.yahoo.com/mail 

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org