You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Sebastian Ho <se...@bii.a-star.edu.sg> on 2004/08/25 08:04:31 UTC

duplication of codes in different Action class

Hi

Scenario :

1. User submits form in JSP1 which Action1 saves to database.
2. Action1 set Form1 into session.
3. Action1 forwards to JSP1 again, which is suppose to display newly
added form with other forms previously added.

How do I make JSP1 to get values from database BEFORE JSP1 displays and
set them into session? I suppose I have to do this in Action1 but for
the first submission of form1, Action1 is not called yet by JSP1.

>>From my analysis, there will be situation where there will be multiple
input sources into a particular JSP. That means I need to have my
'update from database and set in session' codes in all the Action
classes that forwards to JSP1? 

In another words, how do I call the update method in Action1 from
Action2 before forwarding to the JSP which display my updated data.

This is duplication of codes and inefficient to me. There must be a
better way to do this in Struts.

My question might be confusing..I am trying my best. Tell me if its
unclear.

Thanks

Sebastian Ho





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


Re: duplication of codes in different Action class

Posted by Sebastian Ho <se...@bii.a-star.edu.sg>.
On Wed, 2004-08-25 at 15:03, Rick Reumann wrote:
> Sebastian Ho wrote:
> 
> > I am already using DispatchAction.
> > 
> > I didn't use the scope in my action-mapping. Instead I use
> > session.setAttribute in my Action.
> 
> More than likely you don't need to do the above (you can give your form 
> Session scope right on the mapping for the Action in your config).
> 
> > The codes to update the actionform is in action1. But I need to update
> > the same form in action2. 
> 
> If you are using a DispatchAction why would you be updating the form in 
> a totally different Action? You normally keep related action tasks 
> together in one DispatchAction.

Maybe I need to refactor my codes. I grouped them into two action
classes but in that particular JSP, methods from both action classes are
used..

> 
> > One way is to duplicate the same codes in both
> > action. Or the common update codes can be executed before a JSP is
> > loaded. The latter will prevent duplicate codes.
> 
> Sorry, it might be a language barrier, but you have me really lost now:) 
> I'm not sure what you are trying to in the above.

Not to worry. Maybe my situation is kinda complex to explain clearly. I
should be able to resolve the problem after I refactor the codes.

> 


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


Re: duplication of codes in different Action class

Posted by Rick Reumann <st...@reumann.net>.
Sebastian Ho wrote:

> I am already using DispatchAction.
> 
> I didn't use the scope in my action-mapping. Instead I use
> session.setAttribute in my Action.

More than likely you don't need to do the above (you can give your form 
Session scope right on the mapping for the Action in your config).

> The codes to update the actionform is in action1. But I need to update
> the same form in action2. 

If you are using a DispatchAction why would you be updating the form in 
a totally different Action? You normally keep related action tasks 
together in one DispatchAction.

> One way is to duplicate the same codes in both
> action. Or the common update codes can be executed before a JSP is
> loaded. The latter will prevent duplicate codes.

Sorry, it might be a language barrier, but you have me really lost now:) 
I'm not sure what you are trying to in the above.


-- 
Rick

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


Re: duplication of codes in different Action class

Posted by Sebastian Ho <se...@bii.a-star.edu.sg>.
I am already using DispatchAction.

I didn't use the scope in my action-mapping. Instead I use
session.setAttribute in my Action.

The codes to update the actionform is in action1. But I need to update
the same form in action2. One way is to duplicate the same codes in both
action. Or the common update codes can be executed before a JSP is
loaded. The latter will prevent duplicate codes.

sebastian


On Wed, 2004-08-25 at 14:26, Rick Reumann wrote:
> Sebastian Ho wrote:
> 
> > Hi
> > 
> > Scenario :
> > 
> > 1. User submits form in JSP1 which Action1 saves to database.
> > 2. Action1 set Form1 into session.
> > 3. Action1 forwards to JSP1 again, which is suppose to display newly
> > added form with other forms previously added.
> > 
> > How do I make JSP1 to get values from database BEFORE JSP1 displays and
> > set them into session? I suppose I have to do this in Action1 but for
> > the first submission of form1, Action1 is not called yet by JSP1.
> > 
> >>From my analysis, there will be situation where there will be multiple
> > input sources into a particular JSP. That means I need to have my
> > 'update from database and set in session' codes in all the Action
> > classes that forwards to JSP1? 
> > 
> > In another words, how do I call the update method in Action1 from
> > Action2 before forwarding to the JSP which display my updated data.
> > 
> > This is duplication of codes and inefficient to me. There must be a
> > better way to do this in Struts.
> > 
> > My question might be confusing..I am trying my best. Tell me if its
> > unclear.
> 
> It's unclear:)
> 
> Some of you terminology might just be wrong which is making it more 
> confusing. For example in step 2 above, are you setting the form in 
> session scope yourself? You normally don't need, or want, to manually do 
> this. You delcare the scope of your form in your action mapping.
> 
> I think what you are wondering about is "How do you get your form 
> populate for your JSP so that that user can alter it?" (I could be wrong 
> here)... anyway I like to use a DispatchAction which has several methods 
> in it... setUp, Update, etc. So your first call when the user clicks on 
> a link would call the setUp method and there you would make sure your 
> form is populated with the data it needs and you forward to your JSP. As 
> a side note, you do not need to be using Session scope for this. Do you 
> have a particular reason why you need to be using Session scope for your 
> form (many times you do, but I'm guessing in this case you don't and you 
> are using the Session because you are not understanding the flow of how 
> Struts operates).
> 


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


Re: duplication of codes in different Action class

Posted by Rick Reumann <st...@reumann.net>.
Sebastian Ho wrote:

> Hi
> 
> Scenario :
> 
> 1. User submits form in JSP1 which Action1 saves to database.
> 2. Action1 set Form1 into session.
> 3. Action1 forwards to JSP1 again, which is suppose to display newly
> added form with other forms previously added.
> 
> How do I make JSP1 to get values from database BEFORE JSP1 displays and
> set them into session? I suppose I have to do this in Action1 but for
> the first submission of form1, Action1 is not called yet by JSP1.
> 
>>>From my analysis, there will be situation where there will be multiple
> input sources into a particular JSP. That means I need to have my
> 'update from database and set in session' codes in all the Action
> classes that forwards to JSP1? 
> 
> In another words, how do I call the update method in Action1 from
> Action2 before forwarding to the JSP which display my updated data.
> 
> This is duplication of codes and inefficient to me. There must be a
> better way to do this in Struts.
> 
> My question might be confusing..I am trying my best. Tell me if its
> unclear.

It's unclear:)

Some of you terminology might just be wrong which is making it more 
confusing. For example in step 2 above, are you setting the form in 
session scope yourself? You normally don't need, or want, to manually do 
this. You delcare the scope of your form in your action mapping.

I think what you are wondering about is "How do you get your form 
populate for your JSP so that that user can alter it?" (I could be wrong 
here)... anyway I like to use a DispatchAction which has several methods 
in it... setUp, Update, etc. So your first call when the user clicks on 
a link would call the setUp method and there you would make sure your 
form is populated with the data it needs and you forward to your JSP. As 
a side note, you do not need to be using Session scope for this. Do you 
have a particular reason why you need to be using Session scope for your 
form (many times you do, but I'm guessing in this case you don't and you 
are using the Session because you are not understanding the flow of how 
Struts operates).


-- 
Rick

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


Re: duplication of codes in different Action class

Posted by Rick Reumann <st...@reumann.net>.
lixin chu wrote:

> so JSP1 should be associated with another Action,
> which fetch data from DB and setAttribute in request
> or session.

Well everything should be going through an Action of some sort so "yes" 
just make sure the form is populated in your Action before forwarding on 
to the JSP.

-- 
Rick

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


Re: duplication of codes in different Action class

Posted by lixin chu <li...@yahoo.com>.
so JSP1 should be associated with another Action,
which fetch data from DB and setAttribute in request
or session.

You should make your Action not the JSP1 available to
the user.

--- Sebastian Ho <se...@bii.a-star.edu.sg> wrote:

> Hi
> 
> Scenario :
> 
> 1. User submits form in JSP1 which Action1 saves to
> database.
> 2. Action1 set Form1 into session.
> 3. Action1 forwards to JSP1 again, which is suppose
> to display newly
> added form with other forms previously added.
> 
> How do I make JSP1 to get values from database
> BEFORE JSP1 displays and
> set them into session? I suppose I have to do this
> in Action1 but for
> the first submission of form1, Action1 is not called
> yet by JSP1.
> 
> >From my analysis, there will be situation where
> there will be multiple
> input sources into a particular JSP. That means I
> need to have my
> 'update from database and set in session' codes in
> all the Action
> classes that forwards to JSP1? 
> 
> In another words, how do I call the update method in
> Action1 from
> Action2 before forwarding to the JSP which display
> my updated data.
> 
> This is duplication of codes and inefficient to me.
> There must be a
> better way to do this in Struts.
> 
> My question might be confusing..I am trying my best.
> Tell me if its
> unclear.
> 
> Thanks
> 
> Sebastian Ho
> 
> 
> 
> 
> 
>
---------------------------------------------------------------------
> 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