01: /* ZKExternalContextImpl.java
02: {{IS_NOTE
03: Purpose:
04:
05: Description:
06:
07: History:
08: Jul 25, 2007 10:03:38 AM , Created by Dennis Chen
09: }}IS_NOTE
10:
11: Copyright (C) 2007 Potix Corporation. All Rights Reserved.
12:
13: {{IS_RIGHT
14: This program is distributed under GPL Version 2.0 in the hope that
15: it will be useful, but WITHOUT ANY WARRANTY.
16: }}IS_RIGHT
17: */
18: package org.zkoss.seam.jsf;
19:
20: import java.io.IOException;
21:
22: import javax.faces.FacesException;
23: import javax.servlet.ServletContext;
24: import javax.servlet.ServletRequest;
25: import javax.servlet.ServletResponse;
26: import javax.servlet.http.HttpServletResponse;
27:
28: import org.apache.commons.lang.NotImplementedException;
29: import org.apache.myfaces.context.servlet.ServletExternalContextImpl;
30: import org.zkoss.seam.ConversationUtil;
31: import org.zkoss.seam.OpenWindow;
32: import org.zkoss.zk.ui.Executions;
33:
34: /**
35: * This class is for integrate ZK with Seam, You should not use this class directly.<br/>
36: * The main purpose of this class is :
37: * <ul>
38: * <li>
39: * Becaus Seam will call redirect() method when a navigation result must be redirected.
40: * When current request is a uiUpdate then use ZK's redirect mechanism to redirect it, other wise just send redirect.
41: * </li>
42: * </ul>
43: *
44: * @author Dennis.Chen
45: *
46: */
47: /**package**/
48: class ZKExternalContextImpl extends ServletExternalContextImpl {
49:
50: ServletContext _servletContext;
51: ServletRequest _servletRequest;
52: ServletResponse _servletResponse;
53:
54: public ZKExternalContextImpl(ServletContext servletContext,
55: ServletRequest servletRequest,
56: ServletResponse servletResponse) {
57: super (servletContext, servletRequest, servletResponse);
58: this ._servletContext = servletContext;
59: this ._servletRequest = servletRequest;
60: this ._servletResponse = servletResponse;
61: }
62:
63: @Override
64: public void redirect(String url) throws IOException {
65: url = ConversationUtil.appendLongRunningConversation(url);
66: if (ZKFacesContextImpl.isCurrentZKUiUpdate()) {
67: //TODO How to Keep MESSAGE?? ( temp long conversation?)
68: OpenWindow ow = ZKFacesContextImpl.getCurrentZKInstance()
69: .getOpenWindow();
70: if (ow != null) {
71: ow.setUrl(url);
72: ow.open();
73: } else {
74: Executions.getCurrent().sendRedirect(url);
75: }
76: } else {
77: if (_servletResponse instanceof HttpServletResponse) {
78: ((HttpServletResponse) _servletResponse)
79: .sendRedirect(url);
80: //FacesContext.getCurrentInstance().responseComplete();
81: } else {
82: throw new IllegalArgumentException(
83: "Only HttpServletResponse supported");
84: }
85: }
86: }
87:
88: public void dispatch(String requestURI) throws IOException,
89: FacesException {
90: throw new NotImplementedException(
91: "dispatch has not supported yet");
92: }
93:
94: }
|