Redirecting to a different page in webwork actions

This recipe covers a very simple concept in JIRA web actions. While writing plugins, we often come across scenarios where we need to navigate to a new page, such as a Dashboard, to browse a new project, or view another issue after the action has executed. JiraWebActionSupport provides a simple method for doing this, which we will see in this recipe.

How to do it...

What if we want to navigate to the Dashboard instead of rendering a success view when an action is executed? What if we can't directly link it from the JSP page or the velocity template because we want to perform something in the action class beforehand?

All you need to do here is to return getRedirect(URL) in the action class's doExecute method (or the appropriate method)! This method will redirect to the specified location after the action method has successfully finished. If there are any errors, it will go to the error page, as the getRedirect() method returns Action.ERROR in that case.

You can force redirect to the URL even if there are errors by using forceRedirect(URL) instead of the getRedirect() method. It doesn't clear the return URL and will always go to the redirect URL.

For example, if we need to return to the Dashboard after SUCCESS, we can do so as follows:

@Override public String doExecute() throws Exception {
    System.out.println("Action invoked. Doing something important before 
    redirecting to Dashboard!");
   return getRedirect("/secure/Dashboard.jspa");
} 

Replacing getRedirect with forceRedirect will take the user to the Dashboard irrespective of the result.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.143.4.181