001: /* NavigationUtil.java
002: {{IS_NOTE
003: Purpose:
004:
005: Description:
006:
007: History:
008: Jul 25, 2007 10:03:38 AM , Created by Dennis Chen
009: }}IS_NOTE
010:
011: Copyright (C) 2007 Potix Corporation. All Rights Reserved.
012:
013: {{IS_RIGHT
014: This program is distributed under GPL Version 2.0 in the hope that
015: it will be useful, but WITHOUT ANY WARRANTY.
016: }}IS_RIGHT
017: */
018: package org.zkoss.seam;
019:
020: import javax.faces.application.NavigationHandler;
021: import javax.faces.context.FacesContext;
022:
023: import org.zkoss.seam.jsf.ZKFacesContextImpl;
024: import org.zkoss.zk.ui.Executions;
025: import org.zkoss.zk.ui.event.EventListener;
026:
027: /**
028: * This Class helps developers do JSF's page navigation in ZK
029: * @author Dennis.Chen
030: *
031: */
032: public class NavigationUtil {
033:
034: private static final int REDIRECT = 0;
035:
036: /**package**/
037: static final int MODAL = 1;
038:
039: // public static final int OVERLAPPED = 2;
040: /**package**/
041: static final int POPUP = 3;
042:
043: /**
044: * navigate current ZK Execution ot uri,
045: * if uri is null, then do nothing. Other wish , the navigation will depends on navigation rule wich specified by JSF
046: * @param uri
047: */
048: static public void navigate(String uri) {
049: navigateTo(uri, REDIRECT, null);
050: }
051:
052: /**package**/
053: static void navigate(String uri, int mode, EventListener listener) {
054: navigateTo(uri, mode, listener);
055: }
056:
057: /**package**/
058: static void navigate(Void uri, int mode, EventListener listener) {
059: navigateTo(null, mode, listener);
060: }
061:
062: /**package**/
063: static void navigateTo(String uri, int mode, EventListener listener) {
064: String style = null;
065: String url = null;
066: // TODO popup, or some else,
067: try {
068: if (uri == null) {
069: return;
070: } else if (isOutcomeViewId(uri)) {
071: url = ConversationUtil
072: .appendLongRunningConversation(uri);
073:
074: if (mode == REDIRECT) {
075: Executions.getCurrent().sendRedirect(url);
076: } else {
077: new OpenWindow(url, mode, style, listener).open();
078: }
079: } else {
080: FacesContext facesContext = FacesContext
081: .getCurrentInstance();
082: if (facesContext == null) {
083: throw new RuntimeException(
084: "Can't find FacesContext");
085: }
086:
087: if (mode != REDIRECT) {
088: OpenWindow ow = new OpenWindow(null, mode, style,
089: listener);
090: ZKFacesContextImpl.getCurrentZKInstance()
091: .setOpenWindow(ow);
092: }
093:
094: NavigationHandler handler = null;
095:
096: handler = facesContext.getApplication()
097: .getNavigationHandler();
098:
099: // handler = new SeamNavigationHandler(handler);
100:
101: handler.handleNavigation(facesContext, null, uri);
102:
103: }
104: } catch (RuntimeException x) {
105: x.printStackTrace();
106: throw x;
107: }
108:
109: }
110:
111: private static boolean isOutcomeViewId(String outcome) {
112: return outcome != null && outcome.startsWith("/");
113: }
114:
115: }
|