You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Martin Morawetz <ma...@kreativezone.at> on 2005/07/18 18:57:46 UTC

instantiation of actionforms in session scope

Hi to all,

I use a formbean within session-scope (declared in
struts-config.xml). However it behaves like it would
be within request-scope. Every new page it gets
instantiated again. I checked the sessionid and
it is every page the same, so I guess am within the
same http-session.

Does anyone have some ideas what the reason may be?

Every hint is highly appreciated.

--
Regards
Martin


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


Re: instantiation of actionforms in session scope

Posted by Martin Morawetz <ma...@kreativezone.at>.
And here comes the solution, damm it.

I put an object with properties which didn't
implement the Serializable Interface into the
Session. In the resin.conf (we still use Resin
Version 2.1.6)
<always-load-session>true</always-load-session>
was set. So when Resin loads the session, it
couldn't load the property and didn't load all
other properties too. That's why I was always
in the same session, but always lost the#
session attributes.

Thanks to all for you input

--
Regards
Martin


Martin Morawetz schrieb:

> 
> 
> Martin Morawetz schrieb:
> 
>> Hi to all,
>>
>> I use a formbean within session-scope (declared in
>> struts-config.xml). However it behaves like it would
>> be within request-scope. Every new page it gets
>> instantiated again. I checked the sessionid and
>> it is every page the same, so I guess am within the
>> same http-session.
>>
> 
> I recognized that I'm not within the same session.
> I didn't notice it earlier, because the new sessions
> get the same id as the old one. Would be interesting
> if struts or Resin (the Servlet-Engine we use) creates
> the session again with every request.
> 
>> Does anyone have some ideas what the reason may be?
>>
>> Every hint is highly appreciated.
>>
>> -- 
>> Regards
>> Martin
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
> 

-- 

Mit freundlichen Grüßen

Vorname Zuname
kreative|zone°

                                                        kreative|zone°
----------------------------------------------------------------------
                                           Kommunikationsagentur GmbH
   browse  : www.kreativezone.at
   e-mail  : empfang@kreativezone.at
   adresse : Hietzinger Hauptstrasse 28, A-1130 Wien
   tel/fax : +43 -1- 8763389-0 / -10


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


Re: instantiation of actionforms in session scope

Posted by Martin Morawetz <ma...@kreativezone.at>.

Martin Morawetz schrieb:

> Hi to all,
> 
> I use a formbean within session-scope (declared in
> struts-config.xml). However it behaves like it would
> be within request-scope. Every new page it gets
> instantiated again. I checked the sessionid and
> it is every page the same, so I guess am within the
> same http-session.
> 

I recognized that I'm not within the same session.
I didn't notice it earlier, because the new sessions
get the same id as the old one. Would be interesting
if struts or Resin (the Servlet-Engine we use) creates
the session again with every request.

> Does anyone have some ideas what the reason may be?
> 
> Every hint is highly appreciated.
> 
> -- 
> Regards
> Martin
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 

-- 

Mit freundlichen Grüßen

Vorname Zuname
kreative|zone°

                                                        kreative|zone°
----------------------------------------------------------------------
                                           Kommunikationsagentur GmbH
   browse  : www.kreativezone.at
   e-mail  : empfang@kreativezone.at
   adresse : Hietzinger Hauptstrasse 28, A-1130 Wien
   tel/fax : +43 -1- 8763389-0 / -10


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


Re: instantiation of actionforms in session scope

Posted by Michael Jouravlev <jm...@gmail.com>.
On 7/20/05, Martin Morawetz <ma...@kreativezone.at> wrote:
> I thought, the supposed behavior is that a bean declared to be within
> session-scope lives within the session as long as the session lives.
> And if it doesn't exist, it gets created by the struts-framework.

Yep. If you use nested business object, you can easily clean the
action form after you finish or cancel your wizard just by setting
reference to null. Otherwize you would have to clean it field by
field...

The catch is that if a user simply leaves the wizard without
explicitly closing it, it will stay in the session.

Michael.

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


Re: instantiation of actionforms in session scope

Posted by Martin Morawetz <ma...@kreativezone.at>.

BHansard@powersystems.rockwell.com schrieb:
> In the case you outlined, wizardForm should be placed into the session 
> scope when leaving the Funds action.

Shouldn't it be in the session scope by specifying
scope="session" in the action tags in the struts-config.xml?

  You are not required to use the
> struts tags to access the data, but if you are using the struts html 
> tags for input etc, you will need to use the html:form tag. If you are 
> not using the struts tags, you should still be able to use the form bean 
> with a standard <jsp:usebean id="wizardForm" scope="session"> You should 
> also be able to access it from other action classes by explicitly 
> calling the getAttribute("wizardForm"). When you say that it is 
> instantiated with every new page, how are you attempting to access the bean?

I use the bean in several pages. The idea is to have something like
a wizard. On every page a part of data gets added to the wizard bean.
Action.execute() provides a ActionForm parameter. By using this
parameter I access the bean.

What happens is that the bean gets created, filled with the parameters
from the request. In the action class I can access it (and I see
the filled in values on the next page). On the following page a new
formular gets filled. Then the bean gets created again, and filled
with the new parameters. The values from the last page are lost.

Now a possible workaround would be to copy the data from the bean
to some wizard-object which I put in session-scope manually. But
I would like to have a workaround-free solution.
I thought, the supposed behavior is that a bean declared to be within
session-scope lives within the session as long as the session lives.
And if it doesn't exist, it gets created by the struts-framework.
Am I wrong?

I mapped the same bean to several actions in the struts-config.xml:

   <form-bean      name="wizardForm"
                   type="com.cp.pub.WizardForm"/>
  	:
  	:
  <action-mappings>
     <action  path="/Funds"
              type="com.cp.pub.DefineContentFundsAction"
              name="wizardForm"
      scope="session">
  </action>
  <action  path="/Main"
              type="com.cp.pub.DefineContentMainAction"
              name="wizardForm"
      scope="session">
  </action>
  <action  path="/Datail"
              type="com.cp.pub.DefineContentDatailAction"
              name="wizardForm"
      scope="session">
  </action>
  	:
  	:



> Martin Morawetz <ma...@kreativezone.at>
> 
> 
>                         Martin Morawetz <ma...@kreativezone.at>
> 
>                         07/19/2005 07:12 AM
>                         Please respond to
>                         "Struts Users Mailing List" <us...@struts.apache.org>
> 
> 	
> 
> To
> 	
> Struts Users Mailing List <us...@struts.apache.org>
> 
> cc
> 	
> 
> Subject
> 	
> Re: instantiation of actionforms in session scope
> 
> 	
> 
> 
> 
> Thanks a lot for your answer.
> 
> 
>  > There could be several poteintal problems.
>  >
>  > 1) make sure the JSP does not have the session=false page directive set.
> 
> It doesn't.
> 
>  > 2) Make sure you are referencing the form using the same name as you
>  > have it defined in the struts config (remember capitalization does 
> count).
> 
> I've checked that and than again, the right bean gets filled with the
> right parameters from the request, so I think the problem isn't the
> configuration. The problem arises on the following pages, where I need
> the data to, but the bean gets instantiated with every new page again.
> The following lines are from my struts-config.xml:
> 
>     <form-bean      name="wizardForm"
>                     type="com.cp.pub.WizardForm"/>
> :
> :
>  <action-mappings>
>    <action  path="/Funds"
>             type="com.cp.pub.DefineContentFundsAction"
>             name="wizardForm"
>     scope="session">
> </action>
> :
> :
> 
>  > 3) Make sure you are accessing the form from within the html:form tag
>  > and that the struts action specified in the form action has the expected
>  > form as the type in the struts config.
>  >
> 
> I don't use html:form-tags. Could that be a problem?
> 
>  >
>  >
>  >
>  >
>  > Hi to all,
>  >
>  > I use a formbean within session-scope (declared in
>  > struts-config.xml). However it behaves like it would
>  > be within request-scope. Every new page it gets
>  > instantiated again. I checked the sessionid and
>  > it is every page the same, so I guess am within the
>  > same http-session.
>  >
>  > Does anyone have some ideas what the reason may be?
>  >
>  > Every hint is highly appreciated.
>  >
> 
> 
> --
> 
> Regards
> Martin
> 
> 
> 
> ---------------------------------------------------------------------
> 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: instantiation of actionforms in session scope

Posted by Martin Morawetz <ma...@kreativezone.at>.
I still have no solution to my problem, but I
tested the application with Tomcat instead of
Resin as Servlet-Engine, and it worked.

Unfortunately we have to deploy the application
with Resin.

I think I will use the workaround and copy all the
formular-data to a seperate object which I put
in Session-Context.

If someone has an idea why it works with Tomcat but
not with Resin, please tell me.

--
Regards,
Martin

BHansard@powersystems.rockwell.com schrieb:
> In the case you outlined, wizardForm should be placed into the session 
> scope when leaving the Funds action. You are not required to use the 
> struts tags to access the data, but if you are using the struts html 
> tags for input etc, you will need to use the html:form tag. If you are 
> not using the struts tags, you should still be able to use the form bean 
> with a standard <jsp:usebean id="wizardForm" scope="session"> You should 
> also be able to access it from other action classes by explicitly 
> calling the getAttribute("wizardForm"). When you say that it is 
> instantiated with every new page, how are you attempting to access the bean?
> Martin Morawetz <ma...@kreativezone.at>
> 
> 
>                         Martin Morawetz <ma...@kreativezone.at>
> 
>                         07/19/2005 07:12 AM
>                         Please respond to
>                         "Struts Users Mailing List" <us...@struts.apache.org>
> 
> 	
> 
> To
> 	
> Struts Users Mailing List <us...@struts.apache.org>
> 
> cc
> 	
> 
> Subject
> 	
> Re: instantiation of actionforms in session scope
> 
> 	
> 
> 
> 
> Thanks a lot for your answer.
> 
> 
>  > There could be several poteintal problems.
>  >
>  > 1) make sure the JSP does not have the session=false page directive set.
> 
> It doesn't.
> 
>  > 2) Make sure you are referencing the form using the same name as you
>  > have it defined in the struts config (remember capitalization does 
> count).
> 
> I've checked that and than again, the right bean gets filled with the
> right parameters from the request, so I think the problem isn't the
> configuration. The problem arises on the following pages, where I need
> the data to, but the bean gets instantiated with every new page again.
> The following lines are from my struts-config.xml:
> 
>     <form-bean      name="wizardForm"
>                     type="com.cp.pub.WizardForm"/>
> :
> :
>  <action-mappings>
>    <action  path="/Funds"
>             type="com.cp.pub.DefineContentFundsAction"
>             name="wizardForm"
>     scope="session">
> </action>
> :
> :
> 
>  > 3) Make sure you are accessing the form from within the html:form tag
>  > and that the struts action specified in the form action has the expected
>  > form as the type in the struts config.
>  >
> 
> I don't use html:form-tags. Could that be a problem?
> 
>  >
>  >
>  >
>  >
>  > Hi to all,
>  >
>  > I use a formbean within session-scope (declared in
>  > struts-config.xml). However it behaves like it would
>  > be within request-scope. Every new page it gets
>  > instantiated again. I checked the sessionid and
>  > it is every page the same, so I guess am within the
>  > same http-session.
>  >
>  > Does anyone have some ideas what the reason may be?
>  >
>  > Every hint is highly appreciated.
>  >
> 
> 
> --
> 
> Regards
> Martin
> 
> 
> 
> ---------------------------------------------------------------------
> 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: instantiation of actionforms in session scope

Posted by BH...@powersystems.rockwell.com.
In the case you outlined, wizardForm should be placed into the session
scope when leaving the Funds action.  You are not required to use the
struts tags to access the data, but if you are using the struts html tags
for input etc, you will need to use the html:form tag.  If you are not
using the struts tags, you should still be able to use the form bean with a
standard <jsp:usebean id="wizardForm" scope="session">  You should also be
able to access it from other action classes by explicitly calling the
getAttribute("wizardForm").  When you say that it is instantiated with
every new page, how are you attempting to access the bean?


                                                                           
             Martin Morawetz                                               
             <martin.morawetz@                                             
             kreativezone.at>                                           To 
                                       Struts Users Mailing List           
             07/19/2005 07:12          <us...@struts.apache.org>            
             AM                                                         cc 
                                                                           
                                                                   Subject 
             Please respond to         Re: instantiation of actionforms in 
               "Struts Users           session scope                       
               Mailing List"                                               
             <user@struts.apac                                             
                  he.org>                                                  
                                                                           
                                                                           
                                                                           





Thanks a lot for your answer.


> There could be several poteintal problems.
>
> 1) make sure the JSP does not have the session=false page directive set.

It doesn't.

> 2) Make sure you are referencing the form using the same name as you
> have it defined in the struts config (remember capitalization does
count).

I've checked that and than again, the right bean gets filled with the
right parameters from the request, so I think the problem isn't the
configuration. The problem arises on the following pages, where I need
the data to, but the bean gets instantiated with every new page again.
The following lines are from my struts-config.xml:

     <form-bean      name="wizardForm"
                     type="com.cp.pub.WizardForm"/>
             :
             :
  <action-mappings>
    <action  path="/Funds"
             type="com.cp.pub.DefineContentFundsAction"
             name="wizardForm"
                 scope="session">
             </action>
             :
             :

> 3) Make sure you are accessing the form from within the html:form tag
> and that the struts action specified in the form action has the expected
> form as the type in the struts config.
>

I don't use html:form-tags. Could that be a problem?

>
>
>
>
> Hi to all,
>
> I use a formbean within session-scope (declared in
> struts-config.xml). However it behaves like it would
> be within request-scope. Every new page it gets
> instantiated again. I checked the sessionid and
> it is every page the same, so I guess am within the
> same http-session.
>
> Does anyone have some ideas what the reason may be?
>
> Every hint is highly appreciated.
>


--

Regards
Martin



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


Re: instantiation of actionforms in session scope

Posted by Martin Morawetz <ma...@kreativezone.at>.
Thanks a lot for your answer.


> There could be several poteintal problems.
> 
> 1) make sure the JSP does not have the session=false page directive set.

It doesn't.

> 2) Make sure you are referencing the form using the same name as you 
> have it defined in the struts config (remember capitalization does count).

I've checked that and than again, the right bean gets filled with the
right parameters from the request, so I think the problem isn't the
configuration. The problem arises on the following pages, where I need
the data to, but the bean gets instantiated with every new page again. 
The following lines are from my struts-config.xml:

     <form-bean      name="wizardForm"
                     type="com.cp.pub.WizardForm"/>
	:
	:
  <action-mappings>
    <action  path="/Funds"
             type="com.cp.pub.DefineContentFundsAction"
             name="wizardForm"
	    scope="session">
	</action>
	:
	:

> 3) Make sure you are accessing the form from within the html:form tag 
> and that the struts action specified in the form action has the expected 
> form as the type in the struts config.
> 

I don't use html:form-tags. Could that be a problem?

> 
> 	
> 
> 
> Hi to all,
> 
> I use a formbean within session-scope (declared in
> struts-config.xml). However it behaves like it would
> be within request-scope. Every new page it gets
> instantiated again. I checked the sessionid and
> it is every page the same, so I guess am within the
> same http-session.
> 
> Does anyone have some ideas what the reason may be?
> 
> Every hint is highly appreciated.
> 


--

Regards
Martin



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


Re: instantiation of actionforms in session scope

Posted by BH...@powersystems.rockwell.com.
There could be several poteintal problems.

1)  make sure the JSP does not have the session=false page directive set.
2)  Make sure you are referencing the form using the same name as you have
it defined in the struts config (remember capitalization does count).
3)  Make sure you are accessing the form from within the html:form tag and
that the struts action specified in the form action has the expected form
as the type in the struts config.




                                                                           
             Martin Morawetz                                               
             <martin.morawetz@                                             
             kreativezone.at>                                           To 
                                       user@struts.apache.org              
             07/18/2005 12:57                                           cc 
             PM                                                            
                                                                   Subject 
                                       instantiation of actionforms in     
             Please respond to         session scope                       
               "Struts Users                                               
               Mailing List"                                               
             <user@struts.apac                                             
                  he.org>                                                  
                                                                           
                                                                           




Hi to all,

I use a formbean within session-scope (declared in
struts-config.xml). However it behaves like it would
be within request-scope. Every new page it gets
instantiated again. I checked the sessionid and
it is every page the same, so I guess am within the
same http-session.

Does anyone have some ideas what the reason may be?

Every hint is highly appreciated.

--
Regards
Martin


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