Re: Implementing "cancel" on a form

2015-10-05 Thread Lukasz Lenart
2015-10-04 20:32 GMT+02:00 Christopher Schultz :
> -BEGIN PGP SIGNED MESSAGE-
> Hash: SHA256
>
> All,
>
> I've got a form which works nicely, and I'd like to add a "cancel"
> button to it. Right now, I have an Action class that implements no
> Struts2-defined interfaces... I just have the typical execute-style
> methods edit() and save(). I'd like to call cancel() when the user
> presses the cancel button.
>
> I've been both reading "Struts 2 in Action" and doing a bit of
> Googling, but it's tough to find resources on implementing "cancel".
>
> I did see something about using a button with a name like
> "redirect-action:index" but it wasn't clear when that redirection
> takes place... before or after the action is invoked.
>
> What am I missing?

You can use DMI (you must enable it first) and then you can use one of
those solution

https://struts.apache.org/docs/html-form-buttons-howto.html
https://struts.apache.org/docs/multiple-submit-buttons.html

basically:



Regards
-- 
Ɓukasz
+ 48 606 323 122 http://www.lenart.org.pl/

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



Re: Implementing "cancel" on a form

2015-10-05 Thread Christoph Nenning
Christopher,

> > -BEGIN PGP SIGNED MESSAGE-
> > Hash: SHA256
> >
> > All,
> >
> > I've got a form which works nicely, and I'd like to add a "cancel"
> > button to it. Right now, I have an Action class that implements no
> > Struts2-defined interfaces... I just have the typical execute-style
> > methods edit() and save(). I'd like to call cancel() when the user
> > presses the cancel button.
> >
> > I've been both reading "Struts 2 in Action" and doing a bit of
> > Googling, but it's tough to find resources on implementing "cancel".
> >
> > I did see something about using a button with a name like
> > "redirect-action:index" but it wasn't clear when that redirection
> > takes place... before or after the action is invoked.
> >
> > What am I missing?
> 
> You can use DMI (you must enable it first) and then you can use one of
> those solution
> 
> https://struts.apache.org/docs/html-form-buttons-howto.html
> https://struts.apache.org/docs/multiple-submit-buttons.html
> 
> basically:
> 
> 
> 

Another option would be to register cancel() as a dedicated action:

http://struts.apache.org/docs/action-configuration.html#ActionConfiguration-ActionMethods

Then you would need another (non-visible) form with an according action 
attribute.



But as cancel should not change server state or involve Database 
operations I would rather use a link (styled as button) instead of 
submitting a form. That gives you just a GET request while a form submit 
usually means a POST-Redirect-GET cycle.


Regards,
Christoph


This Email was scanned by Sophos Anti Virus


Re: Implementing "cancel" on a form

2015-10-04 Thread Christopher Schultz
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA256

Martin,

On 10/4/15 7:40 PM, Martin Gainty wrote:
> by form you mean Struts 1.3 StrutsForm?

No, an S2 form. I'm sorry I wasn't specific, though it should have
been obvious since I mentioned I was reading "Struts /2/ in Action".

I'm just talking about an HTML , not formal class called a Form
or anything like that.

> if your form class extends ActionForm then implement reset as seen
> here: public FooActionForm extends
> org.apache.struts.action.ActionForm { @Override public void
> reset(org.apache.struts.action.ActionMapping arg0, 
> HttpServletRequest arg1)  { arg1.getSession(false);.invalidate();
> //invalidate session } }

Logging the user out when they cancel a form seems rather drastic,
don't you think? Also, I don't think the above code does what you
think it does.

>   class="org.apache.struts2.s1.ActionFormResetInterceptor"/>  file="struts-integration.xml" />

Nope. If your examples are for Struts 1.3, there are no interceptors
available there.

>   
>  namespace="/integration">  
> ...    
>   
> 
>  
> struts-validation.xml:  class="org.apache.struts2.showcase.validation.SubmitApplication" 
> method="cancelApplication"> 
> /validation/storeErrorsAcrossRequestCancel.jsp 
> 
> 
> /validation/StoreErrorsAcrossRequestCancel.jsp:  <%@taglib
> prefix="s" uri="/struts-tags" %> example of errors
> page
>  Application Canceled  value="/validation/storeErrorsAcrossRequestExample.jsp" />  href="%{#url}">Try Again  
> 
> you can also shortcut Cancel in jsp with 
> session.removeAttribute("fu");//clean out *all* session attribs 
> session.invalidate();   //invalidate session

Yeah, none of that makes any sense.

What I've done in the meantime is a heavy-handed approach and written
my own interceptor:

  public String intercept(ActionInvocation actionInvocation)
throws Exception
  {
if(ActionContext.getContext().getParameters().containsKey(CANCEL_KEY
))
{
  if(log.isDebugEnabled())
log.debug("Form contains " + CANCEL_KEY
  + " parameter; redirecting to "
  + CANCEL_FORWARD + " forward");

  return CANCEL_FORWARD;
}
else
  return actionInvocation.invoke();
  }

- -chris
-BEGIN PGP SIGNATURE-
Comment: GPGTools - http://gpgtools.org

iQIcBAEBCAAGBQJWEgOLAAoJEBzwKT+lPKRYCW8QAJXVecgOl8oUM/vN8VnnwkUF
pSzN2UNGdjwsqbjLnS8Y5Ck59RpVTjrT0mrZKfsMA6iO1fCKEqPqLu/Oi3F+dwf7
kcqzJ8maVr2ttP1KUokHBX4xeL/JZJOImRT3iQiZ9dtPKm/uSsOrQxnhaz/8dqco
d2SQZSsLqc6mh01k6T2eTfmkk2KtuT4CloCiTsxmbtgkBs2wU44irdGtq9l1yTQE
LA62VgKJhMqzQ9dLsoisos+J0GMXb2On7fmoo5RI91ta1xPa3bX5c1+WrKqCilaZ
nnwV21cKpXLOEPbeZf8Ch0CkvxzVX5rqa+z02HQ08Q4fpSzo61lIb1+XsKaEFX0s
Nvz5mrjX5jrqgXqnvHejVqnggi1YVUlDwAI5wzDlss2CbNf6XT6wE8qLxsKQvuVt
6cqJmt3beRTOPN2pTebFvpSDZkJCWn+BmXLmzDV1G0s6MQZeQhN4R1UDj8FAjlQi
wAB82fLoLlvc5R9dekHSsA+DQvouQ1aoLGawxc4iz/Ky252z1sJbH+Q/yUcvI5U7
v2gqVEgH/oktq6TxLl45A5L9/IHu1wC/X9LfU0ywMnKGV+kLwSHw1xesqkBDuJSy
7/6Y073T19p1cIGgZpbCjJrYBCJV+ro8Rp37wDU3btQTBkop3MxOa8JTdpFGatcU
nEqRURGGlN2mdLKfd8xQ
=eq0t
-END PGP SIGNATURE-

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