0

I have developed a screen to authenticate user using Struts2 Jquery Plugin. It is partially loaded in to target div. In case of success everything is fine but in case of failure i don't know what to do. The documentation doesn't talk anything about it at all.

@Action(value = "/validate-login", className = "LoginAction", results = {
    @Result(location = "startup-after-login.jsp", name = "success") })
public String execute() throws Exception {

    super.addActionError("test");
    throw new Exception();

    //return SUCCESS;
}

service.validateUser might throw an exception when authentication fails. Not sure how to handle those and show it as error in front end.

There is one more link which talks about it but i couldn't get it working successfully.

strust 2 (jquery plugin) show action exceptions as ajax error

Thanks for your help.

Community
  • 1
  • 1
Lokesha S
  • 75
  • 1
  • 4
  • 16
  • Consider to return a result corresponding to an exception you throw somewhere in the code. Be concise by posting [SSCCE](http://sscce.org). – Roman C Jan 13 '14 at 12:05
  • Thanks for the reply. I just want to get this error message as JSON and display it as dialog. I am planning to add interceptor to the stack. It just catches any exception which returns JSON as output. I will have CompleteNotifyTopics , Based on error code i can open a dialog. Can someone let me know how to produce custom JSON result? – Lokesha S Jan 23 '14 at 14:37
  • What do you mean a *custom JSON result*? – Roman C Jan 23 '14 at 15:30
  • whenever an exception is thrown i won't be handling it in action, instead it will be thrown up the stack. I will have an interceptor where i will catch exception and return my own result type whose purpose is to create Json with error messages and related error details. – Lokesha S Jan 23 '14 at 17:34
  • Is your own result type not json or what? – Roman C Jan 23 '14 at 19:57
  • I want to write custom result type , It returns JSON – Lokesha S Jan 24 '14 at 13:28
  • Why do you need a custom result type?! Show the code you have written. – Roman C Jan 24 '14 at 13:32

1 Answers1

0

Ok, No proper answer so far. After struggling for lot of time, I just did further more research into struts2 jquery plugin it seems this plugin has lot of problems then solutions. Any ways for this question: You need to make sure you are returning http code which is not equal to 200. This could be achieved by overriding default Exception handler interceptor and set the value to anything more than 400. I am setting it to 400 (Bad Request) then struts2 jquery plugin identifies it has error else it always treats it has success response though actually there was error raised in the back end. Once you raise the error you can have OnErrorTopics and process the response accordingly.

Lokesha S
  • 75
  • 1
  • 4
  • 16