Re: action chaining without resetting action forms
Ted Husted wrote: Volker Krebs wrote: I'm intrested, can you please post a patched JAR. We are doing some Action chaning in our application. OK, see http://husted.com/struts/resources/invoke.zip Sorry, but with your patched struts.jar my Application won't deploy. NoClassDefFoundError: org/apache/struts/action/ActionMessages I'm using Tomcat 3.2.3 on Win2000. Also I had to make the invokeAction Method public. But the solution Paul Devine suggested: return action2.perform( ); is almost what I wanted to do. (Pass a diffrent formBean with my action). Volker -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
Re: action chaining without resetting action forms
Hello Ted, If anyone is interested, I can post a patched JAR. But then they really, really need to tell me that it works, or else this will never be committed. I've finally managed to test it. I had to integrated in the newest nightly build, because we are using some new tags. But after that it worked fine in our Application. It still has to be integrated in the ActionServlet for tiles (ActionComponentServlet), and the invokeAction method has to become public. I would appreciate if this would be committed. thanks, Volker -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
Re: action chaining without resetting action forms
Hi Mohammed sorry for my late reply. If you want to use use action chaining to accomplish this, you will need to define both Action1 and Action2 mappings in your struts-config.xml file. In the Action2 mapping, define a forward... for let's call it login_failed which points to /action1.do. I can send on the exact syntax if you need that (i just don't have it with me right now.)In Action1 mapping you will define a forward... to something like process_login which points to your Action2 /action2.do . Alternatively you could just hard code the dependency in your Action1 class, i.e. in the perform() method of Action1, you could do a return action2.perform( ); depends what makes sense in the context of your application Please let me know if this does not help - Paul - Original Message - From: Mohammed [EMAIL PROTECTED] To: Struts Users Mailing List [EMAIL PROTECTED] Sent: Thursday, December 06, 2001 2:56 AM Subject: Re: action chaining without resetting action forms Hi Paul, I have a similar Problem. From a link I invoke Action1 whichn sendes a Form to the Browser. With a submit on this form I am invoking Action2. In the Action2Form I am validating the user input. In the Action2 itself I invoke a registeruser() methode of a database Object. When the username in the userfield already exist in the database I want to tell the user he should try another username. To do this I forward to Action1 again. what should I do so that the - Original Message - From: Paul Devine [EMAIL PROTECTED] To: Struts Users Mailing List [EMAIL PROTECTED] Sent: Thursday, December 06, 2001 4:33 AM Subject: Re: action chaining without resetting action forms Joe I chain actions the way you describe. When you say the action form is reset before the next action gets to process, do you mean (a) specifically that your ActionForm object's reset() method is invoked and you have overridden that method to clear out the form? Or do you mean (b) the object goes out of scope and a new one gets constructed by the time the second action gets to process ? (or something else you are observing?) If it's (a) then I don't know of any in-built mechanisms to solve this, you may need to write some code to manage that yourself. - Paul - Original Message - From: Joe Faith [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, December 05, 2001 11:54 AM Subject: action chaining without resetting action forms Hi, I want to 'chain' actions, by setting the forward of one to be 'my_action.do' The problem is that this resets the action form before calling the next action. Is there anyway to prevent this, or am I chaining actions in the wrong way? thanks -- Joe Faith http://www.runtime-collective.com T: (+44) 01273 234294 M: (+44) 07968 292064 -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED] -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED] -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
Re: action chaining without resetting action forms
This is the same as my ActionMultiplexer thing that I wrote. Basically I have created a DefaultActionForm class with a `action' property. Ditto created `AppBaseAction' and `AppActionServlet' and these two know about each other. The way Struts 1.0 is that the ActionForm bean is populated from request.getParameter(). Of course if you multiplex [ call an action from another action ] you can have problems because the Java Servlet 2.2 specs does not have mutable reguest.,getParameters(). So I had to cheat in my AppActionServlet to make it look in the `request.getAttributes( button_name )' first if there is no value set then `request.getParameter( button_name )'. This is how I got around the action form properly. It is the only way because Struts is simply using the standard Java Servlet API for request.getRequestDispatcher() when you call `return mapping.findForward( ... );' I think you have two choices Ted: 1) Go through the request.getRequestDispatcher() API (This is more consistent with Suns API, so I choose this option) 2) Fake it, dont go throught the request dispatcher, call the action directly. Therefore find the Action in the ActionMappings and then create the Bean as a normal newInstance() and call processAction() directly. May be I am not making a lot sense here. In either case you may to do I have done prioritise bean population request.getAttribute and request.getParameter(). Say if you want to override the action command before you forward to the sub action you do as you would with the request dispatcher API. request.setAttribute( action, promptForm ); mapping.findForward( dispatch-dvd-order ); Whatever action and action form dispatch-dvd-order invoke would cause the action form bean, for sake of argument DvdOrderForm, property action to be set with promptForm (provided of course it has accessor/mutator DVDActionForm extends DefaultActionForm { String action=; String getAction() { } void setAction(String) { ... } } -- Peter Pilgrim ++44 (0)207-545-9923 //_\\ Mathematics is essentially the study of islands of === disparate subjects in a sea of ignorance. || ! || Andrew Wiles _ Message History From: Ted Husted [EMAIL PROTECTED] on 06/12/2001 19:51 EST Please respond to Struts Users Mailing List [EMAIL PROTECTED] To: Struts Users Mailing List [EMAIL PROTECTED] cc: Subject: Re: action chaining without resetting action forms When you forward to a JSP, the original ActionForm and ActionMapping are left alone. As it stands, when you forward to another Action, the ActionServlet uses the same processing cycle it used for the first Action. If an ActionForm is specified by the mapping, the ActionServlet will try to populate it. It will also put the mapping for the second Action into the request, obliterating any trace of the original Action. As far as your ViewAction knows, it is the one and only Action that has been called. If your response-Action is using its own data structures, and is not looking for the Struts ActionForm or ActionMapping in the request, or is hiding them in delegates, then you are all set. Of course, if it is not using the ActionForm or ActionMapping, why not make it a standalone servlet? At which point it would be exactly the same as forwarding to a JSP. A current DEV idea is to provide for invoking the Action directly. This would work better for you, and is an easy change to the ActionServlet. This would also allow you to share ActionForms and ActionMappings between Action objects. -- Ted Husted, Husted dot Com, Fairport NY USA. -- Custom Software ~ Technical Services. -- Tel +1 716 737-3463 -- http://www.husted.com/struts/ Cakalic, James P. wrote: Upshot is, if there are any problems forwarding between Actions that are essentially different than the semantics of forwarding from an Action to a JSP, I really need to know what they are and how they can be addressed. Best regards, Jim Cakalic -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED] -- This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and destroy this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden. -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
RE: action chaining without resetting action forms
Thanks for your response, Ted. I (or another developer on my team) will be driving a spike on this in the next few days but I wanted to parrot back what I understood for confirmation. Assume that I cleanly separate the intent of my actions into RequestAction and ViewAction. The mappings for RequestActions may specify ActionForms because they are the targets of HTTP posts and I want a form to be created, auto-populated, and validated. The ActionForm instance is automatically stored in either the request or session scope by the ActionServlet. The RequestAction's perform method is called and it goes about doing whatever it needs to do to satisfy the request. When finished, the RequestAction uses ActionMapping to find an ActionForward by name and returns that to the ActionServlet. This ActionForward actually specifies a ViewAction which ActionServlet forwards to. Since the ActionServlet is also the target for the ViewAction URI, it intercepts the request and processes it just like any other Action. Now my intent would be that ViewActions are not typically the direct targets of posts. They are only ever forward targets from other Actions. As a consequence, I would not specify an ActionForm in the mapping for a ViewAction. If I understand your comments correctly, that means that the ActionForm instance constructed by the RequestAction is still in the specified servlet collection from where it can be directly retrieved by the ViewAction and used to generate the response. If there is no ActionForm, the ViewAction could choose to balk or go ahead and generate the HTML with form elements blank. That way it _could_ be the target of a post to generate an initial blank form. If I may, I'd like to take a moment to explain my reasoning here. I know that a large part of Struts is the taglibs that can be used to get the Java code out of JSPs. I think that is an admirable step. However, in the organization that I consult with, there is a very clear delineation between site designers (the graphical types that also write the HTML) and Java developers (who write the business logic and hook the HTML pages into it). The delivery timeframes are short and these two groups work in parallel. Site designers don't understand and don't like seeing JSP tags littered throughout their HTML. Nor do many of the tools they use as inclusion of JSP tags in the HTML results in invalid markup. Finally, JSP (and similar technologies) force different groups to collaborate on a common document. Since the contents of the document, at least here, are in continuous revision until just before delivery there is a significant collision between the groups. Casting about for an alternative that would solve these problems and still offer decent performance is what finally led me to XMLC. http://xmlc.enhydra.org/project/aboutProject/index.html I think this ability to incorporate alternate presentation generation strategies into the Struts framework will be an increasing concern. I've seen mention on the mail lists about the ability to incorporate Velocity as a JSP alternative. And, while not yet ready for prime time as far as I can tell, the XML/XSL strategy will be maturing. Regardless of which presentation generation strategy is used, a mature, robust, tested, and open-source MVC framework (ie, Struts) will be needed to solve all the _other_ problems relevant to best practice construction of web applications. An effective solution, clearly elucidated, will go a long way to attracting the JSP-opponents and the JSP-wary to Struts. Thanks again, Ted, for your attention and guidance. Best regards, Jim Cakalic -Original Message- From: Ted Husted [mailto:[EMAIL PROTECTED]] Sent: Thursday, December 06, 2001 6:52 PM To: Struts Users Mailing List Subject: Re: action chaining without resetting action forms When you forward to a JSP, the original ActionForm and ActionMapping are left alone. As it stands, when you forward to another Action, the ActionServlet uses the same processing cycle it used for the first Action. If an ActionForm is specified by the mapping, the ActionServlet will try to populate it. It will also put the mapping for the second Action into the request, obliterating any trace of the original Action. As far as your ViewAction knows, it is the one and only Action that has been called. If your response-Action is using its own data structures, and is not looking for the Struts ActionForm or ActionMapping in the request, or is hiding them in delegates, then you are all set. Of course, if it is not using the ActionForm or ActionMapping, why not make it a standalone servlet? At which point it would be exactly the same as forwarding to a JSP. A current DEV idea is to provide for invoking the Action directly. This would work better for you, and is an easy change to the ActionServlet. This would also allow you to share ActionForms and ActionMappings between Action objects. -- Ted Husted
Re: action chaining without resetting action forms
Cakalic, James P. wrote: Now my intent would be that ViewActions are not typically the direct targets of posts. They are only ever forward targets from other Actions. As a consequence, I would not specify an ActionForm in the mapping for a ViewAction. If I understand your comments correctly, that means that the ActionForm instance constructed by the RequestAction is still in the specified servlet collection from where it can be directly retrieved by the ViewAction and used to generate the response. If there is no ActionForm, the ViewAction could choose to balk or go ahead and generate the HTML with form elements blank. That way it _could_ be the target of a post to generate an initial blank form. Yes, if it knew what the ActionForm was called. This information would be in the mapping for the original request, which would not be available in the normal course. If conventional forwarding it to be used, it would be my suggestion that the ActionForm, or equivalent, be forwarded under a predetermined name. One way to go would be to use the attribute property of ActionMapping to give all the ActionForms the same name in the request. If I may, I'd like to take a moment to explain my reasoning here. I know that a large part of Struts is the taglibs that can be used to get the Java code out of JSPs. I think that is an admirable step. However, in the organization that I consult with, there is a very clear delineation between site designers (the graphical types that also write the HTML) and Java developers (who write the business logic and hook the HTML pages into it). The delivery timeframes are short and these two groups work in parallel. Site designers don't understand and don't like seeing JSP tags littered throughout their HTML. Nor do many of the tools they use as inclusion of JSP tags in the HTML results in invalid markup. Finally, JSP (and similar technologies) force different groups to collaborate on a common document. Since the contents of the document, at least here, are in continuous revision until just before delivery there is a significant collision between the groups. Casting about for an alternative that would solve these problems and still offer decent performance is what finally led me to XMLC. http://xmlc.enhydra.org/project/aboutProject/index.html Enhydra and Barracuda seem like solid endeavors. Also a good choice. I think this ability to incorporate alternate presentation generation strategies into the Struts framework will be an increasing concern. I've seen mention on the mail lists about the ability to incorporate Velocity as a JSP alternative. And, while not yet ready for prime time as far as I can tell, the XML/XSL strategy will be maturing. Regardless of which presentation generation strategy is used, a mature, robust, tested, and open-source MVC framework (ie, Struts) will be needed to solve all the _other_ problems relevant to best practice construction of web applications. An effective solution, clearly elucidated, will go a long way to attracting the JSP-opponents and the JSP-wary to Struts. Personally, I'd think in terms of putting whatever you have in mind for an Action into a servlet, so that it is not coupled directly with Struts. I have been working with the Velocity team on finishing the work Geir started last spring. We should have an improved VelServlet available for testing next week. The approach here is to forward to a Velocity servlet to render the page, so that they are drop-in replacement for JSPs. Again, you should really think about doing the same approach for your project. -- Ted Husted, Husted dot Com, Fairport NY USA. -- Custom Software ~ Technical Services. -- Tel +1 716 737-3463 -- http://www.husted.com/struts/ -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
RE: action chaining without resetting action forms
Ted Husted wrote: Personally, I'd think in terms of putting whatever you have in mind for an Action into a servlet, so that it is not coupled directly with Struts. I have been working with the Velocity team on finishing the work Geir started last spring. We should have an improved VelServlet available for testing next week. The approach here is to forward to a Velocity servlet to render the page, so that they are drop-in replacement for JSPs. Again, you should really think about doing the same approach for your project. Okay. Sounds like an interesting possibility. I guess I should monitor the Velocity site/mail list for this announcement? Thanks again. Jim font size=1Confidentiality Warning: This e-mail contains information intended only for the use of the individual or entity named above. If the reader of this e-mail is not the intended recipient or the employee or agent responsible for delivering it to the intended recipient, any dissemination, publication or copying of this e-mail is strictly prohibited. The sender does not accept any responsibility for any loss, disruption or damage to your data or computer system that may occur while using data contained in, or transmitted with, this e-mail. If you have received this e-mail in error, please immediately notify us by return e-mail. Thank you.
Re: action chaining without resetting action forms
Cakalic, James P. wrote: Okay. Sounds like an interesting possibility. I guess I should monitor the Velocity site/mail list for this announcement? Thanks again. I'm sure I would bring it up here. -- Ted Husted, Husted dot Com, Fairport NY USA. -- Custom Software ~ Technical Services. -- Tel +1 716 737-3463 -- http://www.husted.com/struts/ -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
Re: action chaining without resetting action forms
The best solution here is to use add a switch to your bean to make its properties immutable. private boolean immutable = false; public void setImmutable(boolean immutable) { this.immutable = immutable; } // ... public setProperty(String property) { if (immutable) exit; this.property = property; If you set this before forwarding the bean, then reset and autopopulate will have no affect. (Unless, of course, reset sets the fields directly. In which case, reset needs to observe immutable, or use the setters instead.) For the nightly build, I've suggested that we add two new methods so that one Action can invoke another, but need some people to test the idea for me. (Since I don't do this sort of thing myself.) This would let you do things like // ... ActionForward forward = servlet.invokeAction(/item/Edit,form,request,response); return forward; To create a new ActionForm to use with invokeAction, you could call ActionForm secondForm = servlet.createActionForm(/item/Edit); and then populate it as you would any ActionForm: ActionForward forward = null; if (secondForm==null) { // .. cope with error } else { EditForm editForm = (EditForm) secondForm; editForm.setArticle(17); editForm.setTitle(Change Me); forward = invokeAction( /item/Edit,editForm,request,response); } // ... return forward; If anyone is interested, I can post a patched JAR. But then they really, really need to tell me that it works, or else this will never be committed. -- Ted Husted, Husted dot Com, Fairport NY USA. -- Custom Software ~ Technical Services. -- Tel +1 716 737-3463 -- http://www.husted.com/struts/ Joe Faith wrote: Hi, I want to 'chain' actions, by setting the forward of one to be 'my_action.do' The problem is that this resets the action form before calling the next action. Is there anyway to prevent this, or am I chaining actions in the wrong way? thanks -- Joe Faith http://www.runtime-collective.com T: (+44) 01273 234294 M: (+44) 07968 292064 -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
Re: action chaining without resetting action forms
Hi, For the nightly build, I've suggested that we add two new methods so that one Action can invoke another, but need some people to test the idea for me. (Since I don't do this sort of thing myself.) If anyone is interested, I can post a patched JAR. But then they really, really need to tell me that it works, or else this will never be committed. I'm intrested, can you please post a patched JAR. We are doing some Action chaning in our application. I want to 'chain' actions, by setting the forward of one to be 'my_action.do' The problem is that this resets the action form before calling the next action. In our Application this works fine. If I forward from one Action to another Action, the form Bean is still known in the second Action. But this might be, because both Actions use the same FormBean in their struts-config name tag as default FormBean. Volker -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
RE: action chaining without resetting action forms
I'm interested (I think) in action-chaining. I'd like to use struts for development in a project just ramping up. However, I plan to _completely_ abandon JSP and use XMLC to generate the presentation. To do this I intended to split processing between a request-Action and a response-Action. The request-Action would be responsible for handling the incoming request by validating the input if needed and acting upon the model -- just like any Action today. The response-Action would take the place of a JSP. It would be responsible for using the results generated by the request-Action to alter the DOM representation of an HTML page using an XMLC-generated class. It would then generate the HTML directly to the response and return null. Upshot is, if there are any problems forwarding between Actions that are essentially different than the semantics of forwarding from an Action to a JSP, I really need to know what they are and how they can be addressed. Best regards, Jim Cakalic -Original Message- From: Volker Krebs [mailto:[EMAIL PROTECTED]] Sent: Thursday, December 06, 2001 6:59 AM To: Struts Users Mailing List Subject: Re: action chaining without resetting action forms Hi, For the nightly build, I've suggested that we add two new methods so that one Action can invoke another, but need some people to test the idea for me. (Since I don't do this sort of thing myself.) If anyone is interested, I can post a patched JAR. But then they really, really need to tell me that it works, or else this will never be committed. I'm intrested, can you please post a patched JAR. We are doing some Action chaning in our application. I want to 'chain' actions, by setting the forward of one to be 'my_action.do' The problem is that this resets the action form before calling the next action. In our Application this works fine. If I forward from one Action to another Action, the form Bean is still known in the second Action. But this might be, because both Actions use the same FormBean in their struts-config name tag as default FormBean. Volker -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED] font size=1Confidentiality Warning: This e-mail contains information intended only for the use of the individual or entity named above. If the reader of this e-mail is not the intended recipient or the employee or agent responsible for delivering it to the intended recipient, any dissemination, publication or copying of this e-mail is strictly prohibited. The sender does not accept any responsibility for any loss, disruption or damage to your data or computer system that may occur while using data contained in, or transmitted with, this e-mail. If you have received this e-mail in error, please immediately notify us by return e-mail. Thank you.
Re: action chaining without resetting action forms
When you forward to a JSP, the original ActionForm and ActionMapping are left alone. As it stands, when you forward to another Action, the ActionServlet uses the same processing cycle it used for the first Action. If an ActionForm is specified by the mapping, the ActionServlet will try to populate it. It will also put the mapping for the second Action into the request, obliterating any trace of the original Action. As far as your ViewAction knows, it is the one and only Action that has been called. If your response-Action is using its own data structures, and is not looking for the Struts ActionForm or ActionMapping in the request, or is hiding them in delegates, then you are all set. Of course, if it is not using the ActionForm or ActionMapping, why not make it a standalone servlet? At which point it would be exactly the same as forwarding to a JSP. A current DEV idea is to provide for invoking the Action directly. This would work better for you, and is an easy change to the ActionServlet. This would also allow you to share ActionForms and ActionMappings between Action objects. -- Ted Husted, Husted dot Com, Fairport NY USA. -- Custom Software ~ Technical Services. -- Tel +1 716 737-3463 -- http://www.husted.com/struts/ Cakalic, James P. wrote: Upshot is, if there are any problems forwarding between Actions that are essentially different than the semantics of forwarding from an Action to a JSP, I really need to know what they are and how they can be addressed. Best regards, Jim Cakalic -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
Re: action chaining without resetting action forms
Volker Krebs wrote: I'm intrested, can you please post a patched JAR. We are doing some Action chaning in our application. OK, see http://husted.com/struts/resources/invoke.zip -- Ted Husted, Husted dot Com, Fairport NY USA. -- Custom Software ~ Technical Services. -- Tel +1 716 737-3463 -- http://www.husted.com/struts/ -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
Re: action chaining without resetting action forms
Joe I chain actions the way you describe. When you say the action form is reset before the next action gets to process, do you mean (a) specifically that your ActionForm object's reset() method is invoked and you have overridden that method to clear out the form? Or do you mean (b) the object goes out of scope and a new one gets constructed by the time the second action gets to process ? (or something else you are observing?) If it's (a) then I don't know of any in-built mechanisms to solve this, you may need to write some code to manage that yourself. - Paul - Original Message - From: Joe Faith [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, December 05, 2001 11:54 AM Subject: action chaining without resetting action forms Hi, I want to 'chain' actions, by setting the forward of one to be 'my_action.do' The problem is that this resets the action form before calling the next action. Is there anyway to prevent this, or am I chaining actions in the wrong way? thanks -- Joe Faith http://www.runtime-collective.com T: (+44) 01273 234294 M: (+44) 07968 292064 -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]