You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Sgarlata Matt <sg...@bah.com> on 2003/08/16 21:36:18 UTC
Re: How to work with DispatchAction ? (please help)
Erez Efrati wrote:
> Matt, thanks for replying, I almost though I'd never see one.. :-)
>
> I've really ran into a wall but somehow got out of it, still I am not
> really happy with the solution which is by the way close to what you
> described.
>
> I still would appreciate your help here:
>
> I have the 'method' field on my RegForm class, and I guess this is
> normal.
> On the RegAction DispatchAction I have 'create' 'edit' and 'update'
> methods.
> I use also a 'action' parameter to distinguish between two different
> workflows, can I avoid it?
I think you can avoid it, but I haven't worked on any wizards using
Struts yet, so I may be wrong. Let me describe the approach that I use
for saving a record where all data is specified on a single screen.
This approach will work for you if you are saving the record to the
database on the last step of your wizard rather than saving to the
database after each step.
Instead of having both a "create" and "update" method I just have a save
method, so in my form I can always have <html:hidden property="method"
value="save">. In the save method I can distinguish between whether I
am creating or updating based on whether or not the record already has
an ID. If the record does have an ID, I am updating and if it doesn't
then I am creating. I think you could do a test like this both in the
action class that does the saving and in your JSP in place of testing
against action.
Will this approach work for you?
Matt
> Here is the JSP (parts of it):
>
> ...
>
> <script type="text/javascript">
> <!--
> // sets the 'method' param
> function setMethod(method) {
> document.forms[0].method.value = method;
> }
>
> //-->
> </script>
>
> <html:form action="/reg.do">
> <html:hidden property="action"/>
> <html:hidden property="method" value="create"/>
> <html:hidden property="page" value="1"/>
>
> ...
>
>
> <c:choose>
> <c:when test="${regForm.action == 'create'}">
> <!-- continue button -->
> <html:submit>
> <bean:message
> key="button.next"/>
> </html:submit>
> </c:when>
> <c:when test="${regForm.action == 'edit'}">
> <!-- save button -->
> <html:submit
> onclick="setMethod('update');">
> <bean:message
> key="button.save"/>
> </html:submit>
> </c:when>
> </c:choose>
>
> </html:form>
>
> If RegAction.update() finds validation errors it needs to go back to the
> editing form, and restore the 'method' value to 'edit' or 'create' but
> it cannot know that once the value has changed to 'update'. That is why
> I keep an 'action' parameter on the side to differ between the two. Is
> there a better way - I hope there is :)
>
> Erez
>
>
> -----Original Message-----
> From: Sgarlata Matt [mailto:sgarlata_matt@bah.com]
> Sent: Saturday, August 16, 2003 7:26 PM
> To: Struts Users Mailing List
> Subject: Re: How to work with DispatchAction ?
>
> Erez Efrati wrote:
>
>
>>I am trying to work with the DispatchAction that everybody is saying
>
> is
>
>>such a good type of action. Say I have a 'RegAction' sub-classing
>>DispatchAction with the following methods: edit, create, and save.
>>
>>I use <html:link page="/reg.do?method='edit' /> to go into edit.
>>
>>My question is:
>>
>>1) Should I keep an action-mapping to each of the methods?
>
>
> No. One of the nice things about DispatchActions is that they only
> require a single action-mapping. One "disadvantage" of a single action
> mapping is that it can only use a single form bean definition. I guess
> theoretically you could have a dispatch action with multiple
> action-mappings that each used different form beans, but I'm getting
> confused just thinking about it ;) My general rule is that one dispatch
>
> action has one action-mapping and one form bean definition.
>
>
>>2) In RegAction.save(), after I've validated the form and found
>
> errors.
>
>>I need to forward back to the input page, but I need to somehow add
>
> the
>
>>'edit' method. How do you recommend doing that? Do I append it to the
>>action-forwards path with '?method=edit' in the action-mapping
>>configuration?
>
>
> Your dispatch actions sound very similar to mine: I have an add method,
> an edit method, and a save method. I also define two forwards: one to
> the form view (<forward name="viewForm">) and one to the "detail" view
> (<forward name="viewDetails">), which is the view the user sees after a
> successful save. If you find errors, shouldn't you just be able to do
> mapping.findForward("viewForm")? The form bean will still be populates
> with the values the user entered even if you are using a session-scoped
> bean :)
>
>
>>Please help,
>>Erez
>
>
> Matt
>
>
> ---------------------------------------------------------------------
> 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
Cleaning Sessions (was: How to work with DispatchAction ?)
Posted by Sgarlata Matt <sg...@bah.com>.
Erez Efrati wrote:
> Yes I see how it helps avoid extra parameter. I am using EJB and I don't
> think there will be any problem with checking the "record" id. I will
> try it and see how goes.
>
> Just for the sake of it I must say that Wizard is a real pain.
> Especially when you try to reuse those pages for updating - it's a
> killer.
Have you ever tried implementing a wizard with web technologies that
have no notion of a session? I had to implement a wizard using Oracle's
PL/SQL and that was no fun at all ;)
> What bothers me also is that since the wizard uses the form on
> session scope, the update uses this scope too. If the user goes into
> update a certain part of its registration (one of the wizard pages) and
> then regrets and goes to another place in the application, it leaves me
> with the form on the session. I am sure there are ways to clean it but I
> haven't got to it yet.
Is there a good way to clean things out of sessions that anyone knows
about? I haven't been able to think of one. The problem is that if a
user opens a new browser window (using File | New Window in IE) then
both windows are using the same session. So you can't have some type of
"clean session" action shared by your whole application because if a
user does something in window A and then does something unrelated in
window B, window B would erase the session info window A needs. Anyone
have thoughts on this? Sorry if it has already been brought up before...
> Thanks,
> Erez
>
> -----Original Message-----
> From: Sgarlata Matt [mailto:sgarlata_matt@bah.com]
> Sent: Saturday, August 16, 2003 9:36 PM
> To: Struts Users Mailing List
> Subject: Re: How to work with DispatchAction ? (please help)
>
> Erez Efrati wrote:
>
>>Matt, thanks for replying, I almost though I'd never see one.. :-)
>>
>>I've really ran into a wall but somehow got out of it, still I am not
>>really happy with the solution which is by the way close to what you
>>described.
>>
>>I still would appreciate your help here:
>>
>>I have the 'method' field on my RegForm class, and I guess this is
>>normal.
>>On the RegAction DispatchAction I have 'create' 'edit' and 'update'
>>methods.
>>I use also a 'action' parameter to distinguish between two different
>>workflows, can I avoid it?
>
>
> I think you can avoid it, but I haven't worked on any wizards using
> Struts yet, so I may be wrong. Let me describe the approach that I use
> for saving a record where all data is specified on a single screen.
> This approach will work for you if you are saving the record to the
> database on the last step of your wizard rather than saving to the
> database after each step.
>
> Instead of having both a "create" and "update" method I just have a save
>
> method, so in my form I can always have <html:hidden property="method"
> value="save">. In the save method I can distinguish between whether I
> am creating or updating based on whether or not the record already has
> an ID. If the record does have an ID, I am updating and if it doesn't
> then I am creating. I think you could do a test like this both in the
> action class that does the saving and in your JSP in place of testing
> against action.
>
> Will this approach work for you?
>
> Matt
>
>
>>Here is the JSP (parts of it):
>>
>>...
>>
>><script type="text/javascript">
>><!--
>> // sets the 'method' param
>> function setMethod(method) {
>> document.forms[0].method.value = method;
>> }
>>
>>//-->
>></script>
>>
>><html:form action="/reg.do">
>> <html:hidden property="action"/>
>> <html:hidden property="method" value="create"/>
>> <html:hidden property="page" value="1"/>
>>
>> ...
>>
>>
>> <c:choose>
>> <c:when test="${regForm.action == 'create'}">
>> <!-- continue button -->
>> <html:submit>
>> <bean:message
>>key="button.next"/>
>> </html:submit>
>> </c:when>
>> <c:when test="${regForm.action == 'edit'}">
>> <!-- save button -->
>> <html:submit
>>onclick="setMethod('update');">
>> <bean:message
>>key="button.save"/>
>> </html:submit>
>> </c:when>
>> </c:choose>
>>
>></html:form>
>>
>>If RegAction.update() finds validation errors it needs to go back to
>
> the
>
>>editing form, and restore the 'method' value to 'edit' or 'create' but
>>it cannot know that once the value has changed to 'update'. That is
>
> why
>
>>I keep an 'action' parameter on the side to differ between the two. Is
>>there a better way - I hope there is :)
>>
>>Erez
>>
>>
>>-----Original Message-----
>>From: Sgarlata Matt [mailto:sgarlata_matt@bah.com]
>>Sent: Saturday, August 16, 2003 7:26 PM
>>To: Struts Users Mailing List
>>Subject: Re: How to work with DispatchAction ?
>>
>>Erez Efrati wrote:
>>
>>
>>
>>>I am trying to work with the DispatchAction that everybody is saying
>>
>>is
>>
>>
>>>such a good type of action. Say I have a 'RegAction' sub-classing
>>>DispatchAction with the following methods: edit, create, and save.
>>>
>>>I use <html:link page="/reg.do?method='edit' /> to go into edit.
>>>
>>>My question is:
>>>
>>>1) Should I keep an action-mapping to each of the methods?
>>
>>
>>No. One of the nice things about DispatchActions is that they only
>>require a single action-mapping. One "disadvantage" of a single
>
> action
>
>>mapping is that it can only use a single form bean definition. I
>
> guess
>
>>theoretically you could have a dispatch action with multiple
>>action-mappings that each used different form beans, but I'm getting
>>confused just thinking about it ;) My general rule is that one
>
> dispatch
>
>>action has one action-mapping and one form bean definition.
>>
>>
>>
>>>2) In RegAction.save(), after I've validated the form and found
>>
>>errors.
>>
>>
>>>I need to forward back to the input page, but I need to somehow add
>>
>>the
>>
>>
>>>'edit' method. How do you recommend doing that? Do I append it to the
>>>action-forwards path with '?method=edit' in the action-mapping
>>>configuration?
>>
>>
>>Your dispatch actions sound very similar to mine: I have an add
>
> method,
>
>>an edit method, and a save method. I also define two forwards: one to
>
>
>>the form view (<forward name="viewForm">) and one to the "detail" view
>
>
>>(<forward name="viewDetails">), which is the view the user sees after
>
> a
>
>>successful save. If you find errors, shouldn't you just be able to do
>
>
>>mapping.findForward("viewForm")? The form bean will still be
>
> populates
>
>>with the values the user entered even if you are using a
>
> session-scoped
>
>>bean :)
>>
>>
>>
>>>Please help,
>>>Erez
>>
>>
>>Matt
>>
>>
>>---------------------------------------------------------------------
>>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
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
RE: How to work with DispatchAction ? (please help)
Posted by Erez Efrati <er...@netmedia.net.il>.
Yes I see how it helps avoid extra parameter. I am using EJB and I don't
think there will be any problem with checking the "record" id. I will
try it and see how goes.
Just for the sake of it I must say that Wizard is a real pain.
Especially when you try to reuse those pages for updating - it's a
killer. What bothers me also is that since the wizard uses the form on
session scope, the update uses this scope too. If the user goes into
update a certain part of its registration (one of the wizard pages) and
then regrets and goes to another place in the application, it leaves me
with the form on the session. I am sure there are ways to clean it but I
haven't got to it yet.
Thanks,
Erez
-----Original Message-----
From: Sgarlata Matt [mailto:sgarlata_matt@bah.com]
Sent: Saturday, August 16, 2003 9:36 PM
To: Struts Users Mailing List
Subject: Re: How to work with DispatchAction ? (please help)
Erez Efrati wrote:
> Matt, thanks for replying, I almost though I'd never see one.. :-)
>
> I've really ran into a wall but somehow got out of it, still I am not
> really happy with the solution which is by the way close to what you
> described.
>
> I still would appreciate your help here:
>
> I have the 'method' field on my RegForm class, and I guess this is
> normal.
> On the RegAction DispatchAction I have 'create' 'edit' and 'update'
> methods.
> I use also a 'action' parameter to distinguish between two different
> workflows, can I avoid it?
I think you can avoid it, but I haven't worked on any wizards using
Struts yet, so I may be wrong. Let me describe the approach that I use
for saving a record where all data is specified on a single screen.
This approach will work for you if you are saving the record to the
database on the last step of your wizard rather than saving to the
database after each step.
Instead of having both a "create" and "update" method I just have a save
method, so in my form I can always have <html:hidden property="method"
value="save">. In the save method I can distinguish between whether I
am creating or updating based on whether or not the record already has
an ID. If the record does have an ID, I am updating and if it doesn't
then I am creating. I think you could do a test like this both in the
action class that does the saving and in your JSP in place of testing
against action.
Will this approach work for you?
Matt
> Here is the JSP (parts of it):
>
> ...
>
> <script type="text/javascript">
> <!--
> // sets the 'method' param
> function setMethod(method) {
> document.forms[0].method.value = method;
> }
>
> //-->
> </script>
>
> <html:form action="/reg.do">
> <html:hidden property="action"/>
> <html:hidden property="method" value="create"/>
> <html:hidden property="page" value="1"/>
>
> ...
>
>
> <c:choose>
> <c:when test="${regForm.action == 'create'}">
> <!-- continue button -->
> <html:submit>
> <bean:message
> key="button.next"/>
> </html:submit>
> </c:when>
> <c:when test="${regForm.action == 'edit'}">
> <!-- save button -->
> <html:submit
> onclick="setMethod('update');">
> <bean:message
> key="button.save"/>
> </html:submit>
> </c:when>
> </c:choose>
>
> </html:form>
>
> If RegAction.update() finds validation errors it needs to go back to
the
> editing form, and restore the 'method' value to 'edit' or 'create' but
> it cannot know that once the value has changed to 'update'. That is
why
> I keep an 'action' parameter on the side to differ between the two. Is
> there a better way - I hope there is :)
>
> Erez
>
>
> -----Original Message-----
> From: Sgarlata Matt [mailto:sgarlata_matt@bah.com]
> Sent: Saturday, August 16, 2003 7:26 PM
> To: Struts Users Mailing List
> Subject: Re: How to work with DispatchAction ?
>
> Erez Efrati wrote:
>
>
>>I am trying to work with the DispatchAction that everybody is saying
>
> is
>
>>such a good type of action. Say I have a 'RegAction' sub-classing
>>DispatchAction with the following methods: edit, create, and save.
>>
>>I use <html:link page="/reg.do?method='edit' /> to go into edit.
>>
>>My question is:
>>
>>1) Should I keep an action-mapping to each of the methods?
>
>
> No. One of the nice things about DispatchActions is that they only
> require a single action-mapping. One "disadvantage" of a single
action
> mapping is that it can only use a single form bean definition. I
guess
> theoretically you could have a dispatch action with multiple
> action-mappings that each used different form beans, but I'm getting
> confused just thinking about it ;) My general rule is that one
dispatch
>
> action has one action-mapping and one form bean definition.
>
>
>>2) In RegAction.save(), after I've validated the form and found
>
> errors.
>
>>I need to forward back to the input page, but I need to somehow add
>
> the
>
>>'edit' method. How do you recommend doing that? Do I append it to the
>>action-forwards path with '?method=edit' in the action-mapping
>>configuration?
>
>
> Your dispatch actions sound very similar to mine: I have an add
method,
> an edit method, and a save method. I also define two forwards: one to
> the form view (<forward name="viewForm">) and one to the "detail" view
> (<forward name="viewDetails">), which is the view the user sees after
a
> successful save. If you find errors, shouldn't you just be able to do
> mapping.findForward("viewForm")? The form bean will still be
populates
> with the values the user entered even if you are using a
session-scoped
> bean :)
>
>
>>Please help,
>>Erez
>
>
> Matt
>
>
> ---------------------------------------------------------------------
> 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