Forward and Redirect

From Documentation
Revision as of 11:45, 19 November 2010 by Tomyeh (talk | contribs)


Forward and Redirect


A Web application's jumping from one URL to another is usually caused by user's clicking on a hyperlink, such as clicking on a button, toolbarbutton, menuitem and a that is associated with the href attribute.

<button label="Next" href="next.zul"/>

It is done at the client without Java code, so it is efficient. However, you could control it at the server (in Java) too, such that you could redirect based on some information that is available only at the server.

Redirect to Another URL

Redirecting to anther URL is straightforward: pass the URL to Executions.sendRedirect(String). A typical use case is to redirect after authenticating user's login.

if (someCondition())
   Executions.sendRedirect("/ready.zul");

You could also ask the browser to open another browser window for a given URL by use of Execution.sendRedirect(String, String).

Forward to Another Page

Sometimes we have to forward to another page. For example, when a user visits a page that requires authorization, we could forward it to a login page[1].

The simplest way is to use the forward directive: <source lang="xml"> <?forward uri="/login.zul" if="${!foo:isLogin()}"?>

where we assume isLogin is an EL function that returns whether the user logins. For more information, please refer to the forEach, if and unless section.


  1. In additions to forwarding, we could popup a window to ask him to login, i.e., without leaving the current desktop

Version History

Last Update : 2010/11/19


Version Date Content
     



Last Update : 2010/11/19

Copyright © Potix Corporation. This article is licensed under GNU Free Documentation License.