Re: ActionForm/Action with edit mode
On Wed, 6 Jun 2001, John Hogan wrote: All, I have a situation where it is desirable to use a form/page for both adding new info and editing existing data. The new info scenario is straight forward struts ActionForm/Action classes. What I'm wrestling with a bit is the edit scenario. I'm wondering if I can stay within the struts framework and still do something like entering a page in edit mode and have it displaying existing user data? It seems this should be possible because that's exactly what the page does for error handling. Has anyone else tackled this one yet? TIA. JohnH _ Get your free E-mail at http://www.ireland.com The Struts example application includes logic that does exactly what you describe -- the same page (subscription.jsp) is used to add new subscriptions, edit old ones, and confirm deletion of old ones. For the edit case, the trick was to forward to an Action that created a form bean prepopulated with the values from the database object, and then forward to the page. Craig
RE: ActionForm/Action with edit mode
Joe, Ted, Your proposed solutions worked well. Thanks. JohnH -Original Message- From: Joe Kepley [mailto:[EMAIL PROTECTED]] Sent: Wednesday, June 06, 2001 5:50 PM To: [EMAIL PROTECTED] Subject: RE: ActionForm/Action with edit mode I solved this one by creating an action that looked at the incoming bean, and if it was null or contained no data (the user was viewing and hadnt edited yet), then the action would populate the bean from a database and pass back with no errors. If a hidden variable (I called it 'process') had been set, then the action would validate the input, then store the new info into the database. Hope that helps, --Joe -Original Message- From: John Hogan [mailto:[EMAIL PROTECTED]] Sent: Wednesday, June 06, 2001 4:29 PM To: [EMAIL PROTECTED] Subject: ActionForm/Action with edit mode All, I have a situation where it is desirable to use a form/page for both adding new info and editing existing data. The new info scenario is straight forward struts ActionForm/Action classes. What I'm wrestling with a bit is the edit scenario. I'm wondering if I can stay within the struts framework and still do something like entering a page in edit mode and have it displaying existing user data? It seems this should be possible because that's exactly what the page does for error handling. Has anyone else tackled this one yet? TIA. JohnH _ Get your free E-mail at http://www.ireland.com
Re: ActionForm/Action with edit mode
Hogan, John wrote: Joe, Ted, Your proposed solutions worked well. Thanks. Here's a simple trick for returning a blank ActionForm for new data-entry. Define a generic Input action, that does nothing but return (new ActionForward(mapping.getInput())); Then whenever you need to get a blank ActionForm, of any type, just create a mapping to the generic Action, specifying a different input property: action path=/bid/Input type=org.wxxi.gavel.lib.Input name=bidForm scope=request validate=false input=/WEB-INF/jsp/bid/Form.jsp /action Or, action path=/donor/Input type=org.wxxi.gavel.lib.Input name=donorForm scope=request validate=false input=/WEB-INF/jsp/donor/Form.jsp /action This way you don't have to check for an add request for each form type. -- Ted Husted, Husted dot Com, Fairport NY USA. -- Custom Software ~ Technical Services. -- Tel 716 737-3463. -- http://www.husted.com/about/struts/
ActionForm/Action with edit mode
All, I have a situation where it is desirable to use a form/page for both adding new info and editing existing data. The new info scenario is straight forward struts ActionForm/Action classes. What I'm wrestling with a bit is the edit scenario. I'm wondering if I can stay within the struts framework and still do something like entering a page in edit mode and have it displaying existing user data? It seems this should be possible because that's exactly what the page does for error handling. Has anyone else tackled this one yet? TIA. JohnH _ Get your free E-mail at http://www.ireland.com
Re: ActionForm/Action with edit mode
If I understand the question, all you have to do is change the form's action to insert or update as the case may be. A good way to do this is to have a task parameter that you would pass to a single action designed to handle both cases. You can do this dymamically using (where key=0 means we're inserting a new record). logic:equal name=myForm property=key value=0 input type=hidden name=task value=insert /logic:equal logic:notEqual name=myForm property=key value=0 input type=hidden name=task value=update /logic:notEqual For an update, visit an Action first, select the record, populate the form, and forward to input. John Hogan wrote: All, I have a situation where it is desirable to use a form/page for both adding new info and editing existing data. The new info scenario is straight forward struts ActionForm/Action classes. What I'm wrestling with a bit is the edit scenario. I'm wondering if I can stay within the struts framework and still do something like entering a page in edit mode and have it displaying existing user data? It seems this should be possible because that's exactly what the page does for error handling. Has anyone else tackled this one yet? TIA. JohnH _ Get your free E-mail at http://www.ireland.com -- Ted Husted, Husted dot Com, Fairport NY USA. -- Custom Software ~ Technical Services. -- Tel 716 737-3463. -- http://www.husted.com/about/struts/
RE: ActionForm/Action with edit mode
I solved this one by creating an action that looked at the incoming bean, and if it was null or contained no data (the user was viewing and hadnt edited yet), then the action would populate the bean from a database and pass back with no errors. If a hidden variable (I called it 'process') had been set, then the action would validate the input, then store the new info into the database. Hope that helps, --Joe -Original Message- From: John Hogan [mailto:[EMAIL PROTECTED]] Sent: Wednesday, June 06, 2001 4:29 PM To: [EMAIL PROTECTED] Subject: ActionForm/Action with edit mode All, I have a situation where it is desirable to use a form/page for both adding new info and editing existing data. The new info scenario is straight forward struts ActionForm/Action classes. What I'm wrestling with a bit is the edit scenario. I'm wondering if I can stay within the struts framework and still do something like entering a page in edit mode and have it displaying existing user data? It seems this should be possible because that's exactly what the page does for error handling. Has anyone else tackled this one yet? TIA. JohnH _ Get your free E-mail at http://www.ireland.com