Re: Dynamic forwardings...
Personally I would like to see this better supported by Struts, and there is also an enhancement request in the bug database (number 866). I have attached a class (ParameterizedActionForward) where you can write something like: return new ParameterizedActionForward( mapping, forwardName, paramName, paramValue) There are some other contructors, and you can also add parameters after the ParameterizedActionForward has been created. It will properly handle if the forward already contains parameter, and encoding of the key and value. - Jan Sorensen --- Martin Cooper [EMAIL PROTECTED] wrote: You can use the forward in struts-config.xml as a base value and append your parameters dynamically. Something like this: ActionForward fwd = mapping.findForward(blue); StringBuffer path = new StringBuffer(fwd.getPath()); path.append(?tableID=) .append(tableID); // where this might have the value foo return new ForwardingActionForward(path.toString()); -- Martin Cooper -Original Message- From:David Corbin [EMAIL PROTECTED] Sent:Sun, 26 Aug 2001 21:07:03 -0400 To: [EMAIL PROTECTED] Subject: Re: Dynamic forwardings... I'm not sure where I'm miscommunication, so I'll go back to the beginning. I have an action list. It expects an parameter tableID, so a link to it looks like http://host/app/list.do?tableID=foo;, and if things are successful, returns a page with a list of items that depend on the tableID. For each item, there is a link generated for action blue that specifies two parameters: tableID itemID (http://host/app/blue.do?tableID=fooitemID=xyzzy). No problem. The action blue requires the two parameters tableID and itemID. Under certain circumstances, the results of the action blue require that list.do?tableID=foo be forwarded. Struts doesn't seem to provide a way to handle this last case. If it does, I don't understand it. David - Original Message - From: Ted Husted [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Sunday, August 26, 2001 7:14 PM Subject: Re: Dynamic forwardings... Typically, there would be a finite number of inputs, and you could have a logical forward for each one. The ActionMappings form an API for the legal entry points to the application. Usually, the only thing that is truly dynamic is a reference into a data source, to look something up. In that case, the link tag can take one or more dynamic parameters, based on the collection of beans used to write it. In that case, the action usually gets the parameters from the request, and uses them to look up whatever is required. David Corbin wrote: I'm definately talking about forward, but my whatever value is dynamic. It's based on input (a parameter) into the action. I don't yet understand the best solution for that. - Original Message - From: Ted Husted [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Sunday, August 26, 2001 2:56 PM Subject: Re: Dynamic forwardings... For a forward, you just put in an encoded query string for the path: forward name=itemAdd path=/do/item/Add?code=whatever/ For an action mapping, you can use the parameter property action path=/do/item/Add ... parameter=add /action and have the action check for the code there String code = mapping.getParameter(); David Corbin wrote: I've got a an action add, which requires a an argument code. One (at least) of the possible forwards needs to specify this code on the forward URL. How can I do that? Thanks David Corbin ___ Visit http://www.visto.com. Find out how companies are linking mobile users to the enterprise with Visto. __ Do You Yahoo!? Make international calls for as low as $.04/minute with Yahoo! Messenger http://phonecard.yahoo.com/ /* * ParameterizedActionForwardTestCase.java * * Created on August 3, 2001, 1:45 PM */ package org.apache.struts.action; import junit.framework.TestCase; import junit.framework.Test; import junit.framework.TestSuite; /** * * @author Jan Sorensen * @version */ public class ParameterizedActionForwardTestCase extends TestCase { /** Creates new ParameterizedActionForwardTestCase * @param name */ public ParameterizedActionForwardTestCase(String name) { super(name); } /** * Set up instance variables required by this test case. */ public void setUp() { mapping = new ActionMapping(); ActionForward forward = new ActionForward(/command.do); forward.setName(test); mapping.addForward(forward
Re: Dynamic forwardings...
I understand the first choice presented below. But I don't understand the second choice. I think I fail to fully understand ActionForm. Are you saying that if I have a populated ActionForm, then all of those arguments get passed on when I forward to another action? - Original Message - From: Ted Husted [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Sunday, August 26, 2001 9:11 PM Subject: Re: Dynamic forwardings... You can construct ActionForwards from scratch, and I have seen people include query strings with that. http://www.mail-archive.com/struts-user@jakarta.apache.org/msg14224.html Personally, I would think about adding these parameters as hidden fields to the ActionForm, use the form instead, and forget about the parameters. Struts automatically populates the ActionForm from the parameters. It would also populate the same or different ActionForm for the second ActionMapping if you forwarded the request. David Corbin wrote: I'm not sure where I'm miscommunication, so I'll go back to the beginning. I have an action list. It expects an parameter tableID, so a link to it looks like http://host/app/list.do?tableID=foo;, and if things are successful, returns a page with a list of items that depend on the tableID. For each item, there is a link generated for action blue that specifies two parameters: tableID itemID (http://host/app/blue.do?tableID=fooitemID=xyzzy). No problem. The action blue requires the two parameters tableID and itemID. Under certain circumstances, the results of the action blue require that list.do?tableID=foo be forwarded. Struts doesn't seem to provide a way to handle this last case. If it does, I don't understand it. David - Original Message - From: Ted Husted [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Sunday, August 26, 2001 7:14 PM Subject: Re: Dynamic forwardings... Typically, there would be a finite number of inputs, and you could have a logical forward for each one. The ActionMappings form an API for the legal entry points to the application. Usually, the only thing that is truly dynamic is a reference into a data source, to look something up. In that case, the link tag can take one or more dynamic parameters, based on the collection of beans used to write it. In that case, the action usually gets the parameters from the request, and uses them to look up whatever is required. David Corbin wrote: I'm definately talking about forward, but my whatever value is dynamic. It's based on input (a parameter) into the action. I don't yet understand the best solution for that. - Original Message - From: Ted Husted [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Sunday, August 26, 2001 2:56 PM Subject: Re: Dynamic forwardings... For a forward, you just put in an encoded query string for the path: forward name=itemAdd path=/do/item/Add?code=whatever/ For an action mapping, you can use the parameter property action path=/do/item/Add ... parameter=add /action and have the action check for the code there String code = mapping.getParameter(); David Corbin wrote: I've got a an action add, which requires a an argument code. One (at least) of the possible forwards needs to specify this code on the forward URL. How can I do that? Thanks David Corbin
Re: Dynamic forwardings...
I think Ted is saying that you can add a property to your ActionForm, and use this property instead of the parameter. So before forwarding you have to set this new property, and then forward as normal. He is also saying the you can populate the property from a hidden field when submitting a jsp-form. Hope this helps, Jan Sorensen --- David Corbin [EMAIL PROTECTED] wrote: I understand the first choice presented below. But I don't understand the second choice. I think I fail to fully understand ActionForm. Are you saying that if I have a populated ActionForm, then all of those arguments get passed on when I forward to another action? - Original Message - From: Ted Husted [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Sunday, August 26, 2001 9:11 PM Subject: Re: Dynamic forwardings... You can construct ActionForwards from scratch, and I have seen people include query strings with that. http://www.mail-archive.com/struts-user@jakarta.apache.org/msg14224.html Personally, I would think about adding these parameters as hidden fields to the ActionForm, use the form instead, and forget about the parameters. Struts automatically populates the ActionForm from the parameters. It would also populate the same or different ActionForm for the second ActionMapping if you forwarded the request. David Corbin wrote: I'm not sure where I'm miscommunication, so I'll go back to the beginning. I have an action list. It expects an parameter tableID, so a link to it looks like http://host/app/list.do?tableID=foo;, and if things are successful, returns a page with a list of items that depend on the tableID. For each item, there is a link generated for action blue that specifies two parameters: tableID itemID (http://host/app/blue.do?tableID=fooitemID=xyzzy). No problem. The action blue requires the two parameters tableID and itemID. Under certain circumstances, the results of the action blue require that list.do?tableID=foo be forwarded. Struts doesn't seem to provide a way to handle this last case. If it does, I don't understand it. David - Original Message - From: Ted Husted [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Sunday, August 26, 2001 7:14 PM Subject: Re: Dynamic forwardings... Typically, there would be a finite number of inputs, and you could have a logical forward for each one. The ActionMappings form an API for the legal entry points to the application. Usually, the only thing that is truly dynamic is a reference into a data source, to look something up. In that case, the link tag can take one or more dynamic parameters, based on the collection of beans used to write it. In that case, the action usually gets the parameters from the request, and uses them to look up whatever is required. David Corbin wrote: I'm definately talking about forward, but my whatever value is dynamic. It's based on input (a parameter) into the action. I don't yet understand the best solution for that. - Original Message - From: Ted Husted [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Sunday, August 26, 2001 2:56 PM Subject: Re: Dynamic forwardings... For a forward, you just put in an encoded query string for the path: forward name=itemAdd path=/do/item/Add?code=whatever/ For an action mapping, you can use the parameter property action path=/do/item/Add ... parameter=add /action and have the action check for the code there String code = mapping.getParameter(); David Corbin wrote: I've got a an action add, which requires a an argument code. One (at least) of the possible forwards needs to specify this code on the forward URL. How can I do that? Thanks David Corbin __ Do You Yahoo!? Make international calls for as low as $.04/minute with Yahoo! Messenger http://phonecard.yahoo.com/
Re: Dynamic forwardings...
If you are forwarding the request, then everything in the request, including the original parameters are forwarded too. So you don't really need to specify the parameters again. If you need to change the parameters, then you could generate a new query string for the next forward, or put the value into the request some other way. If I was forwarding from one Action to another, I might use my own object for the parameters I was passing, and have the Action check for that before using what was in the request. One likely object would be the ActionForm for the next mapping. If the ActionForms had the tableID and itemID properties, you could pass the information there instead of the going to the request parameters directly. A query string, like ?tableID=thisitemID, is what a HTML form using type=GET generates when it is submitted. When the controller receives the request, it doesn't care (or really know) if the request came from an embedded query string or a HTML form, everything is handled the same way. So, an ActionForm is place to store the parameters of a GET or POST request. If the name of the parameter matches the name of a property, then the controller copies the value over. So form.getThis() and request.getParameter(this) become equivalent. If there is already an ActionForm in the request, then the controller calls reset() and repopulates it (via BeanUtils.populate). To use an ActionForm to pass information from one Action to another, it would needs a readonly flag that would keep reset() and the other mutators from changing any of the existing values. Since the controller reuses ActionForms, they can be a great way pass information along -- so long as you can keep the controller from messing with it along the way. I can understand why people might want to generate an ActionForward with a new set of parameters, and wouldn't vote against it, but personally it seems like a kludge to me. Once the request is received, I believe the expected parameters should be encapsulated in the ActionForm (thereby documenting them), and any cross-Action communications should take place via ActionForms. If an ActionForm is meant to be forwarded, like a value object, then it can be written so that the mutators (including reset()) can be switched off and on. Though, of course, whatever design works best for you is always the best design ;-) -- Ted Husted, Husted dot Com, Fairport NY USA. -- Custom Software ~ Technical Services. -- Tel +1 716 737-3463 -- http://www.husted.com/about/struts/ David Corbin wrote: I understand the first choice presented below. But I don't understand the second choice. I think I fail to fully understand ActionForm. Are you saying that if I have a populated ActionForm, then all of those arguments get passed on when I forward to another action? - Original Message - From: Ted Husted [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Sunday, August 26, 2001 9:11 PM Subject: Re: Dynamic forwardings... You can construct ActionForwards from scratch, and I have seen people include query strings with that. http://www.mail-archive.com/struts-user@jakarta.apache.org/msg14224.html Personally, I would think about adding these parameters as hidden fields to the ActionForm, use the form instead, and forget about the parameters. Struts automatically populates the ActionForm from the parameters. It would also populate the same or different ActionForm for the second ActionMapping if you forwarded the request. David Corbin wrote: I'm not sure where I'm miscommunication, so I'll go back to the beginning. I have an action list. It expects an parameter tableID, so a link to it looks like http://host/app/list.do?tableID=foo;, and if things are successful, returns a page with a list of items that depend on the tableID. For each item, there is a link generated for action blue that specifies two parameters: tableID itemID (http://host/app/blue.do?tableID=fooitemID=xyzzy). No problem. The action blue requires the two parameters tableID and itemID. Under certain circumstances, the results of the action blue require that list.do?tableID=foo be forwarded. Struts doesn't seem to provide a way to handle this last case. If it does, I don't understand it. David - Original Message - From: Ted Husted [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Sunday, August 26, 2001 7:14 PM Subject: Re: Dynamic forwardings... Typically, there would be a finite number of inputs, and you could have a logical forward for each one. The ActionMappings form an API for the legal entry points to the application. Usually, the only thing that is truly dynamic is a reference into a data source, to look something up. In that case, the link tag can take one or more dynamic parameters, based on the collection of beans used to write it. In that case
Re: Dynamic forwardings...
For a forward, you just put in an encoded query string for the path: forward name=itemAdd path=/do/item/Add?code=whatever/ For an action mapping, you can use the parameter property action path=/do/item/Add ... parameter=add /action and have the action check for the code there String code = mapping.getParameter(); David Corbin wrote: I've got a an action add, which requires a an argument code. One (at least) of the possible forwards needs to specify this code on the forward URL. How can I do that? Thanks David Corbin
Re: Dynamic forwardings...
I'm definately talking about forward, but my whatever value is dynamic. It's based on input (a parameter) into the action. I don't yet understand the best solution for that. - Original Message - From: Ted Husted [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Sunday, August 26, 2001 2:56 PM Subject: Re: Dynamic forwardings... For a forward, you just put in an encoded query string for the path: forward name=itemAdd path=/do/item/Add?code=whatever/ For an action mapping, you can use the parameter property action path=/do/item/Add ... parameter=add /action and have the action check for the code there String code = mapping.getParameter(); David Corbin wrote: I've got a an action add, which requires a an argument code. One (at least) of the possible forwards needs to specify this code on the forward URL. How can I do that? Thanks David Corbin
Re: Dynamic forwardings...
Typically, there would be a finite number of inputs, and you could have a logical forward for each one. The ActionMappings form an API for the legal entry points to the application. Usually, the only thing that is truly dynamic is a reference into a data source, to look something up. In that case, the link tag can take one or more dynamic parameters, based on the collection of beans used to write it. In that case, the action usually gets the parameters from the request, and uses them to look up whatever is required. David Corbin wrote: I'm definately talking about forward, but my whatever value is dynamic. It's based on input (a parameter) into the action. I don't yet understand the best solution for that. - Original Message - From: Ted Husted [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Sunday, August 26, 2001 2:56 PM Subject: Re: Dynamic forwardings... For a forward, you just put in an encoded query string for the path: forward name=itemAdd path=/do/item/Add?code=whatever/ For an action mapping, you can use the parameter property action path=/do/item/Add ... parameter=add /action and have the action check for the code there String code = mapping.getParameter(); David Corbin wrote: I've got a an action add, which requires a an argument code. One (at least) of the possible forwards needs to specify this code on the forward URL. How can I do that? Thanks David Corbin
Re: Dynamic forwardings...
I'm not sure where I'm miscommunication, so I'll go back to the beginning. I have an action list. It expects an parameter tableID, so a link to it looks like http://host/app/list.do?tableID=foo;, and if things are successful, returns a page with a list of items that depend on the tableID. For each item, there is a link generated for action blue that specifies two parameters: tableID itemID (http://host/app/blue.do?tableID=fooitemID=xyzzy). No problem. The action blue requires the two parameters tableID and itemID. Under certain circumstances, the results of the action blue require that list.do?tableID=foo be forwarded. Struts doesn't seem to provide a way to handle this last case. If it does, I don't understand it. David - Original Message - From: Ted Husted [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Sunday, August 26, 2001 7:14 PM Subject: Re: Dynamic forwardings... Typically, there would be a finite number of inputs, and you could have a logical forward for each one. The ActionMappings form an API for the legal entry points to the application. Usually, the only thing that is truly dynamic is a reference into a data source, to look something up. In that case, the link tag can take one or more dynamic parameters, based on the collection of beans used to write it. In that case, the action usually gets the parameters from the request, and uses them to look up whatever is required. David Corbin wrote: I'm definately talking about forward, but my whatever value is dynamic. It's based on input (a parameter) into the action. I don't yet understand the best solution for that. - Original Message - From: Ted Husted [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Sunday, August 26, 2001 2:56 PM Subject: Re: Dynamic forwardings... For a forward, you just put in an encoded query string for the path: forward name=itemAdd path=/do/item/Add?code=whatever/ For an action mapping, you can use the parameter property action path=/do/item/Add ... parameter=add /action and have the action check for the code there String code = mapping.getParameter(); David Corbin wrote: I've got a an action add, which requires a an argument code. One (at least) of the possible forwards needs to specify this code on the forward URL. How can I do that? Thanks David Corbin
Re: Dynamic forwardings...
You can construct ActionForwards from scratch, and I have seen people include query strings with that. http://www.mail-archive.com/struts-user@jakarta.apache.org/msg14224.html Personally, I would think about adding these parameters as hidden fields to the ActionForm, use the form instead, and forget about the parameters. Struts automatically populates the ActionForm from the parameters. It would also populate the same or different ActionForm for the second ActionMapping if you forwarded the request. David Corbin wrote: I'm not sure where I'm miscommunication, so I'll go back to the beginning. I have an action list. It expects an parameter tableID, so a link to it looks like http://host/app/list.do?tableID=foo;, and if things are successful, returns a page with a list of items that depend on the tableID. For each item, there is a link generated for action blue that specifies two parameters: tableID itemID (http://host/app/blue.do?tableID=fooitemID=xyzzy). No problem. The action blue requires the two parameters tableID and itemID. Under certain circumstances, the results of the action blue require that list.do?tableID=foo be forwarded. Struts doesn't seem to provide a way to handle this last case. If it does, I don't understand it. David - Original Message - From: Ted Husted [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Sunday, August 26, 2001 7:14 PM Subject: Re: Dynamic forwardings... Typically, there would be a finite number of inputs, and you could have a logical forward for each one. The ActionMappings form an API for the legal entry points to the application. Usually, the only thing that is truly dynamic is a reference into a data source, to look something up. In that case, the link tag can take one or more dynamic parameters, based on the collection of beans used to write it. In that case, the action usually gets the parameters from the request, and uses them to look up whatever is required. David Corbin wrote: I'm definately talking about forward, but my whatever value is dynamic. It's based on input (a parameter) into the action. I don't yet understand the best solution for that. - Original Message - From: Ted Husted [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Sunday, August 26, 2001 2:56 PM Subject: Re: Dynamic forwardings... For a forward, you just put in an encoded query string for the path: forward name=itemAdd path=/do/item/Add?code=whatever/ For an action mapping, you can use the parameter property action path=/do/item/Add ... parameter=add /action and have the action check for the code there String code = mapping.getParameter(); David Corbin wrote: I've got a an action add, which requires a an argument code. One (at least) of the possible forwards needs to specify this code on the forward URL. How can I do that? Thanks David Corbin
Re: Dynamic forwardings...
You can use the forward in struts-config.xml as a base value and append your parameters dynamically. Something like this: ActionForward fwd = mapping.findForward(blue); StringBuffer path = new StringBuffer(fwd.getPath()); path.append(?tableID=) .append(tableID); // where this might have the value foo return new ForwardingActionForward(path.toString()); -- Martin Cooper -Original Message- From:David Corbin [EMAIL PROTECTED] Sent:Sun, 26 Aug 2001 21:07:03 -0400 To: [EMAIL PROTECTED] Subject: Re: Dynamic forwardings... I'm not sure where I'm miscommunication, so I'll go back to the beginning. I have an action list. It expects an parameter tableID, so a link to it looks like http://host/app/list.do?tableID=foo;, and if things are successful, returns a page with a list of items that depend on the tableID. For each item, there is a link generated for action blue that specifies two parameters: tableID itemID (http://host/app/blue.do?tableID=fooitemID=xyzzy). No problem. The action blue requires the two parameters tableID and itemID. Under certain circumstances, the results of the action blue require that list.do?tableID=foo be forwarded. Struts doesn't seem to provide a way to handle this last case. If it does, I don't understand it. David - Original Message - From: Ted Husted [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Sunday, August 26, 2001 7:14 PM Subject: Re: Dynamic forwardings... Typically, there would be a finite number of inputs, and you could have a logical forward for each one. The ActionMappings form an API for the legal entry points to the application. Usually, the only thing that is truly dynamic is a reference into a data source, to look something up. In that case, the link tag can take one or more dynamic parameters, based on the collection of beans used to write it. In that case, the action usually gets the parameters from the request, and uses them to look up whatever is required. David Corbin wrote: I'm definately talking about forward, but my whatever value is dynamic. It's based on input (a parameter) into the action. I don't yet understand the best solution for that. - Original Message - From: Ted Husted [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Sunday, August 26, 2001 2:56 PM Subject: Re: Dynamic forwardings... For a forward, you just put in an encoded query string for the path: forward name=itemAdd path=/do/item/Add?code=whatever/ For an action mapping, you can use the parameter property action path=/do/item/Add ... parameter=add /action and have the action check for the code there String code = mapping.getParameter(); David Corbin wrote: I've got a an action add, which requires a an argument code. One (at least) of the possible forwards needs to specify this code on the forward URL. How can I do that? Thanks David Corbin ___ Visit http://www.visto.com. Find out how companies are linking mobile users to the enterprise with Visto.