3

Is there a way to make a struts action do nothing? I don't want to do anything after my action is performed. Every single action in the project I inherited (794 of them) are redirectAction. But I don't want to redirect. I just want to stay on the same page.

What can I do to just stay on the same page? I want like

<result name="success" type="doNothing"></result>

Is there something I can do to get this behavior? Or even fake it?

corsiKa
  • 81,495
  • 25
  • 153
  • 204

3 Answers3

2

Return ActionSupport.NONE.

What's the usecase? What would an action do that wouldn't return anything?

Dave Newton
  • 158,873
  • 26
  • 254
  • 302
  • I'm using display tag to manage the list of files on the page, so it handles removing the file from the list when I click delete. The action is just a callback to the server to actually delete the file from the database. So if I get a success result, I don't need to do anything. I'm just fine staying on the same page. So I'm looking for something where when I go `return SUCCESS` in my method, my struts config basically goes "Oh you were successful, as I expected. I don't have to do anything..." – corsiKa Nov 22 '12 at 22:35
  • @corsiKa ... ActionSupport.NONE? Although not having a success/failure status seems weird to me. – Dave Newton Nov 23 '12 at 00:04
  • It's like a Linux command. If you `cp /path/to/file /other/path/to/file` you don't get an output of `1 file copied`. It's just expected that if there was no output, it went as expected. So I might `return ERROR` or whatever that is in my Java method. If that's the case, I have a handler for that. But I'm still returning `SUCCESS` out of that in case someone else in some other method wants to make it explicit on the screen (presumably because they're using a front end library that doesn't automatically remove like mine does.) – corsiKa Nov 23 '12 at 03:53
  • tl;dr I'd like to intercept the success and turn it into nothing in my struts config, not in my Java code, so the Java code can be reused. I suppose I could make a second method that calls the first one and `if(result.equals(SUCCESS)) return ActionSupport.NONE;` – corsiKa Nov 23 '12 at 03:55
  • @corsika It still returns a success code, you just don't see it. IMO you're doing it wrong. You can implement a PreResultListener, and really introduce some non-local, non-obvious behavior, or just create a new result type that... keeps status away from the view layer, which is weird to me. – Dave Newton Nov 23 '12 at 04:31
  • That's the whole point though: I want the status to get to the view layer. It's just that in this particular instance of using the status, I want to do nothing with it, where most times I want to redirect. – corsiKa Nov 23 '12 at 04:47
  • I think you are reinveintig AJAX behavior, but using POST :/ This is the strangest discussion I've ever read about Struts2, +1 at both, thanks for making my day (really, no sarcasm). P.S: no feedback is good for Linux, on WebApp it violates Jacob Nielsen's Web Usability principles: "Remove any ambiguity regarding the consequences of an action (e.g. clicking on delete/remove/purchase)."... but inheriting 794 Actions written by others violates "self-preservation" principles, so... :) – Andrea Ligios Nov 23 '12 at 13:21
  • @corsika How will status get back to the view layer if the action doesn't return anything?! – Dave Newton Nov 23 '12 at 15:14
  • @Andrea there is no ambiguity. The record is removed from the screen. The workflow is that the widget removes the record from the screen, then tells the webapp that the record was deleted. If there's an error, my ` – corsiKa Nov 23 '12 at 15:47
  • @Dave That's the entire point of the question! I want to return success to the view layer. And I want the view layer to go "Okay, cool. Since it was successful, I don't want to change pages... I just want to stay right here." – corsiKa Nov 23 '12 at 15:48
  • @corsika You specifically said you *didn't* want it to do anything. What you want is Ajax, *not* to return nothing. Or, depending on how this non-Struts tag works, you might be able to use a forward. I told you how to make an action do nothing. If your view requires something different, you need to articulate what it *actually* needs. – Dave Newton Nov 23 '12 at 15:53
  • @corsika you are right, it is pretty obvious for an vigilant user, nevertheless it violates (in a forgettable way...) Web Usability... let's say you click on "delete" then you suddendly go out for a coffee... and when you return, you don't remember which was the description of the record to be deleted. In that case the visual recognition won't work. For this reason, when you delete for example a mail from GMail, you will get a small, persistent (not splash) message saying "The conversation has been deleted". By the way is just splitting hairs :) – Andrea Ligios Nov 23 '12 at 16:07
0

Try making the ActionForward execute method return null where you would normally have returned. For example, mapping.findForward("something"); - just return null; instead.

Mxyk
  • 10,678
  • 16
  • 57
  • 76
malkoty
  • 99
  • 9
0

Http is a request/response protocol, you have to send something. When I have a similair situation on an ajax page, I simply map the SUCCESS return code to an HttpResultHeader type with a return code of 200.

user497087
  • 1,561
  • 3
  • 24
  • 41