You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by chamal desilva <ch...@yahoo.com> on 2006/06/04 06:51:06 UTC

Controlling Reset method

Hi,

As I know the reset method of a form bean is called
automatically when a action tries to add the form bean
to session or retrieve it.

Is there a way that we can stop the reset method being
called.


========================================================================
This is what I am trying to do.

I have two form beans for Customer and Account and two
actions to "view account list of customer" and "view
account details". First action is linked with Customer
bean and it display the list of accounts owned by the
customer. The second action is linked with Account
bean and it shows the details of account selected by
user.

public void Customer extends ActionForm
{
	Vector accounts = new Vector(); //Elements of this
vector contains Account beans

	//other attributes and methods


}


public void Account extends ActionForm
{
	//attributes and methods

}




For examle let's think there are four Accounts in
accounts vector. The first action displays this list
on a JSP. User clicks on first account and views
details. Then user goes back and clicks on second
account. Then the data of first account object is
reset and gets lost. This is my problem/


=========================================================================

Thanking You,
Chamal.

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

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


Re: Controlling Reset method

Posted by chamal desilva <ch...@yahoo.com>.
Hi Scott,

Thanks a lot for your reply. It was very useful.

Thanking You,
Chamal.

--- Scott Van Wart <sc...@indosoft.ca> wrote:

> chamal desilva wrote:
> > Dear Scott ,
> >
> > Thanks for your reply. 
> >
> > "If you're viewing the second account, why would
> you
> > need data for the 
> > first account?  If it's a problem of losing the
> > customer ID for the 
> > "
> >
> > I need the first account data because it is in the
> > Vector of Customer bean. So the first
> item(Account) of
> > vector will be reset when struts reset the data.
> >
> > Thanking You,
> > Chamal. 
> >   
> Can you simply load it into the bean again? 
> Typically when I set 
> something up like this (parent child relationship,
> where selecting a 
> parent lists the children, and you can click on each
> child), I'll have 
> actions like ShowAccountsAction and
> ShowAccountAction.  I use a 
> ShowCustomerForm, which takes a customer ID, and
> this form is passed to 
> the ShowAccountsAction, which populates the array so
> the subsequent page 
> can list the accounts.  When you click on an
> account, the 
> ShowAccountAction gets called, and is passed in a
> ShowAccountForm (which 
> has an account ID).  The ShowAccountAction populates
> the bean with a 
> single account.
> 
> When the account is shown, because of the
> parent-child relationship, I 
> can provide a "Back" button which will re-populate
> the ShowCustomerForm 
> with the customer ID (looked up through the account
> ID), and the account 
> list will be displayed again.  By separating
> everything, you don't have 
> to worry about what you keep in memory.  Struts
> calls the reset() method 
> on your form bean because it wants to use the form
> for something else.  
> So separate everything out and you won't have to
> worry about keeping the 
> whole list of accounts in a bean across page
> requests.
> 
> - Scott
> 
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> user-unsubscribe@struts.apache.org
> For additional commands, e-mail:
> user-help@struts.apache.org
> 
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

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


Re: Controlling Reset method

Posted by Scott Van Wart <sc...@indosoft.ca>.
chamal desilva wrote:
> Dear Scott ,
>
> Thanks for your reply. 
>
> "If you're viewing the second account, why would you
> need data for the 
> first account?  If it's a problem of losing the
> customer ID for the 
> "
>
> I need the first account data because it is in the
> Vector of Customer bean. So the first item(Account) of
> vector will be reset when struts reset the data.
>
> Thanking You,
> Chamal. 
>   
Can you simply load it into the bean again?  Typically when I set 
something up like this (parent child relationship, where selecting a 
parent lists the children, and you can click on each child), I'll have 
actions like ShowAccountsAction and ShowAccountAction.  I use a 
ShowCustomerForm, which takes a customer ID, and this form is passed to 
the ShowAccountsAction, which populates the array so the subsequent page 
can list the accounts.  When you click on an account, the 
ShowAccountAction gets called, and is passed in a ShowAccountForm (which 
has an account ID).  The ShowAccountAction populates the bean with a 
single account.

When the account is shown, because of the parent-child relationship, I 
can provide a "Back" button which will re-populate the ShowCustomerForm 
with the customer ID (looked up through the account ID), and the account 
list will be displayed again.  By separating everything, you don't have 
to worry about what you keep in memory.  Struts calls the reset() method 
on your form bean because it wants to use the form for something else.  
So separate everything out and you won't have to worry about keeping the 
whole list of accounts in a bean across page requests.

- Scott


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


Re: Controlling Reset method

Posted by chamal desilva <ch...@yahoo.com>.
Dear Scott ,

Thanks for your reply. 

"If you're viewing the second account, why would you
need data for the 
first account?  If it's a problem of losing the
customer ID for the 
"

I need the first account data because it is in the
Vector of Customer bean. So the first item(Account) of
vector will be reset when struts reset the data.

Thanking You,
Chamal. 



--- Scott Van Wart <sc...@indosoft.ca> wrote:

> chamal desilva wrote:
> > For examle let's think there are four Accounts in
> > accounts vector. The first action displays this
> list
> > on a JSP. User clicks on first account and views
> > details. Then user goes back and clicks on second
> > account. Then the data of first account object is
> > reset and gets lost. This is my problem/
> If you're viewing the second account, why would you
> need data for the 
> first account?  If it's a problem of losing the
> customer ID for the 
> account, just make sure you populate the customer ID
> in the action that 
> handles the "back" action associated with viewing
> the account.
> 
> - Scott
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> user-unsubscribe@struts.apache.org
> For additional commands, e-mail:
> user-help@struts.apache.org
> 
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

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


Re: Controlling Reset method

Posted by Scott Van Wart <sc...@indosoft.ca>.
chamal desilva wrote:
> For examle let's think there are four Accounts in
> accounts vector. The first action displays this list
> on a JSP. User clicks on first account and views
> details. Then user goes back and clicks on second
> account. Then the data of first account object is
> reset and gets lost. This is my problem/
If you're viewing the second account, why would you need data for the 
first account?  If it's a problem of losing the customer ID for the 
account, just make sure you populate the customer ID in the action that 
handles the "back" action associated with viewing the account.

- Scott

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