You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Adam Hardy <ah...@cyberspaceroad.com> on 2003/08/08 10:20:31 UTC

Re: intuitively to get new Id to next action when old Id is in request?

Thanks for the input everyone but I can't say I've found a solution that 
stands out as "the way to do it" yet.

I need a technique that I can consistently use across the whole app. Up 
to this point I have been using the formbean to get my hands on the data 
in the action. I've got the following various places where I need the id 
of the object being edited:

- to fetch the rest of the object's properties for display
- to fetch data for dropdown boxes
- to fetch data for child objects

Up till now in all of these I was getting the id from the formbean. But 
now that won't work. Because I have hooked two actions together the id 
in the formbean in the 2nd action in question is out-of-date.

For consistency's sake I didn't want to start doing different data 
retrieval in different places - here from the request, here from the 
formbean, here from the session etc.

Or am I being too purist?

ansuman_behera wrote:
> what if there is a restriction that the developers should not be using hidden variables? what do you do in this case?
> 
> -----Original Message-----
> From: Rohit Aeron [mailto:rzaeron@kanbay.com]
> Sent: Friday, August 08, 2003 11:54 AM
> To: Struts Users Mailing List
> Subject: RE: method to get new Id to next action when old Id is in
> request?
> 
> 
> Try putting up id as a hidden variable...
> 
> Eg:
> 
> <html:hidden name="FormBean" property="id"/>
> 
> 
> it would work 
> 
> regards
> Rohit
> 
> -----Original Message-----
> From: Adam Hardy [mailto:ahardy.struts@cyberspaceroad.com] 
> Sent: Friday, August 08, 2003 2:56 AM
> To: Struts Users Mailing List
> Subject: method to get new Id to next action when old Id is in request?
> 
> I have two actions chained together. They both take the same formbean. 
> The first is sectionInsert.do and the second, which sectionInsert 
> forwards to on success, is sectionEdit.do
> 
> sectionInsert.do receives the properties of a Section in the request 
> parameters, including id=0 where it is 0 because it does not exist in 
> the DB yet. So it inserts the new Section into the DB and returns the 
> new id, which is needed by sectionEdit to put into the html for the edit 
> page.
> 
> I originally thought I could save the new id to the formbean and this 
> would get passed on, but sectionEdit instantiates its own formbean and 
> fills it with the request parameters - include id=0.
> 
> Is there an intuitive way of passing on the new id?
> 
> I already use sectionEdit.do as a first action by calling it with an id 
> on a querystring, where the formbean picks it up. I would like to use a 
> method that is easy for both these situations.
> 
> I'd appreciate any inspiration.
> Adam
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
> 
> 
> 
> *----------
> This message and any attachment(s) is intended only for the use of the addressee(s) and may contain information that is PRIVILEGED and CONFIDENTIAL. If you are not the intended addressee(s), you are hereby notified that any use, distribution, disclosure or copying of this communication is strictly prohibited. If you have received this communication in error, please erase all copies of the message and its attachment(s) and notify the sender or Kanbay postmaster immediately.
> 
> Any views expressed in this message are those of the individual sender and not of Kanbay.
> 
> Although we have taken steps to ensure that this e-mail and any attachment(s) are free from any virus, we advise that in keeping with good computing practice the recipient should ensure they are actually virus free.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
> 
> 


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


Re: get new Id to next action continued....

Posted by Adam Hardy <ah...@cyberspaceroad.com>.
Yes, fits the bill almost 100%, except I now have to change my base 
Action class to accept a forward object back from my child Action, where 
before I was just passing back the forward name and doing the 
findForward in the base class.

I might fudge it and return an object so I can return either the name 
string or the actual forward itself.... :0



Reinhard wrote:
>>I did it with just a new ActionForward. I think my issue is a different
>>kettle of fish to yours.
> 
> 
> The primary motivation may differ, but we end close to the same.
> I now use an extended ActionConfig and added a new findForward(), where I can 
> evaluate the request/session-attributes.
> In the new findForward I create new ActionForward-Instances.
> Works fine for my needs and it's quite comfortable to configure different 
> actions, having only one action-class.
> I think, the findForward() is quite in the middle of the chain, so you could 
> prepare the request/session for the next action.
> 
> cheers Reinhard 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
> 
> 


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


Re: get new Id to next action continued....

Posted by Reinhard <un...@public-files.de>.
> I did it with just a new ActionForward. I think my issue is a different
> kettle of fish to yours.

The primary motivation may differ, but we end close to the same.
I now use an extended ActionConfig and added a new findForward(), where I can 
evaluate the request/session-attributes.
In the new findForward I create new ActionForward-Instances.
Works fine for my needs and it's quite comfortable to configure different 
actions, having only one action-class.
I think, the findForward() is quite in the middle of the chain, so you could 
prepare the request/session for the next action.

cheers Reinhard 

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


Re: get new Id to next action continued....

Posted by Adam Hardy <ah...@cyberspaceroad.com>.
Reinhard wrote:
> I think you'll need your own ActionMapping class too. Than you can reset the 
> request-pool (which should happen at redirection) and/or change whatever you 
> need. 

I did it with just a new ActionForward. I think my issue is a different 
kettle of fish to yours.

I am not sure of what struts does with the request when forwarding from 
one action to the next. I did not configure the forward of the first 
action to do a redirect, emphatically.

I think struts created a new formbean, or at least reinitialised the old 
bean.

I also think struts wrote my forward's querystring parameters into the 
request on leaving the first action. Did it reinitialise its request 
parameter collection from the http request? I don't know.

Perhaps some expert can clarify that here?


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


Re: intuitively to get new Id to next action when old Id is in request?

Posted by Reinhard <un...@public-files.de>.
> because I'm moving from one action to a second action within the scope
> of the same request 

I think I got that. Not sure whether I got your problem completely.

I created an ActionMapping class before, just to change the action-path 
dynamically. Now I needed more information to configure an action and I 
reached the same class ActionMapping (with your help).

I think you'll need your own ActionMapping class too. Than you can reset the 
request-pool (which should happen at redirection) and/or change whatever you 
need. 

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


Re: intuitively to get new Id to next action when old Id is in request?

Posted by Adam Hardy <ah...@cyberspaceroad.com>.
because I'm moving from one action to a second action within the scope 
of the same request - I think. In fact, I'm not sure.

I know if I create my own actionforward, I can write to the querystring, 
but I haven't done that yet. Will have to wait til after lunch.

Theoretically if it works that means that the second action gets a new 
request object, but I think that is only the case when the action 
forward is a redirect.



Reinhard wrote:
>>I am looking at sticking the new id on the querystring of the
>>actionforward path, but struts throws an exception ... 
> 
> 
> Sorry about my question, but don't share querystring and request the same 
> accessability and lifetime? 
> What's the benefit of querystring over the request?
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
> 
> 


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


Re: intuitively to get new Id to next action when old Id is in request?

Posted by Reinhard <un...@public-files.de>.
> I am looking at sticking the new id on the querystring of the
> actionforward path, but struts throws an exception ... 

Sorry about my question, but don't share querystring and request the same 
accessability and lifetime? 
What's the benefit of querystring over the request?

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


Re: intuitively to get new Id to next action when old Id is in request?

Posted by Adam Hardy <ah...@cyberspaceroad.com>.
I am looking at sticking the new id on the querystring of the 
actionforward path, but struts throws an exception saying the 
configuration is frozen - can I configure that differently or would I 
have to create my own clone instance of the action forward?



Adam Hardy wrote:
> Thanks for the input everyone but I can't say I've found a solution that 
> stands out as "the way to do it" yet.
> 
> I need a technique that I can consistently use across the whole app. Up 
> to this point I have been using the formbean to get my hands on the data 
> in the action. I've got the following various places where I need the id 
> of the object being edited:
> 
> - to fetch the rest of the object's properties for display
> - to fetch data for dropdown boxes
> - to fetch data for child objects
> 
> Up till now in all of these I was getting the id from the formbean. But 
> now that won't work. Because I have hooked two actions together the id 
> in the formbean in the 2nd action in question is out-of-date.
> 
> For consistency's sake I didn't want to start doing different data 
> retrieval in different places - here from the request, here from the 
> formbean, here from the session etc.
> 
> Or am I being too purist?
> 
> ansuman_behera wrote:
> 
>> what if there is a restriction that the developers should not be using 
>> hidden variables? what do you do in this case?
>>
>> -----Original Message-----
>> From: Rohit Aeron [mailto:rzaeron@kanbay.com]
>> Sent: Friday, August 08, 2003 11:54 AM
>> To: Struts Users Mailing List
>> Subject: RE: method to get new Id to next action when old Id is in
>> request?
>>
>>
>> Try putting up id as a hidden variable...
>>
>> Eg:
>>
>> <html:hidden name="FormBean" property="id"/>
>>
>>
>> it would work
>> regards
>> Rohit
>>
>> -----Original Message-----
>> From: Adam Hardy [mailto:ahardy.struts@cyberspaceroad.com] Sent: 
>> Friday, August 08, 2003 2:56 AM
>> To: Struts Users Mailing List
>> Subject: method to get new Id to next action when old Id is in request?
>>
>> I have two actions chained together. They both take the same formbean. 
>> The first is sectionInsert.do and the second, which sectionInsert 
>> forwards to on success, is sectionEdit.do
>>
>> sectionInsert.do receives the properties of a Section in the request 
>> parameters, including id=0 where it is 0 because it does not exist in 
>> the DB yet. So it inserts the new Section into the DB and returns the 
>> new id, which is needed by sectionEdit to put into the html for the 
>> edit page.
>>
>> I originally thought I could save the new id to the formbean and this 
>> would get passed on, but sectionEdit instantiates its own formbean and 
>> fills it with the request parameters - include id=0.
>>
>> Is there an intuitive way of passing on the new id?
>>
>> I already use sectionEdit.do as a first action by calling it with an 
>> id on a querystring, where the formbean picks it up. I would like to 
>> use a method that is easy for both these situations.
>>
>> I'd appreciate any inspiration.
>> Adam
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>>
>>
>>
>> *----------
>> This message and any attachment(s) is intended only for the use of the 
>> addressee(s) and may contain information that is PRIVILEGED and 
>> CONFIDENTIAL. If you are not the intended addressee(s), you are hereby 
>> notified that any use, distribution, disclosure or copying of this 
>> communication is strictly prohibited. If you have received this 
>> communication in error, please erase all copies of the message and its 
>> attachment(s) and notify the sender or Kanbay postmaster immediately.
>>
>> Any views expressed in this message are those of the individual sender 
>> and not of Kanbay.
>>
>> Although we have taken steps to ensure that this e-mail and any 
>> attachment(s) are free from any virus, we advise that in keeping with 
>> good computing practice the recipient should ensure they are actually 
>> virus free.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>>
>>
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
> 
> 


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