KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > guiframework > event > handlers > NextPageHandler


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.tools.guiframework.event.handlers;
25
26 import com.sun.enterprise.tools.guiframework.exception.FrameworkException;
27 import com.sun.enterprise.tools.guiframework.view.HandlerContext;
28 import com.sun.enterprise.tools.guiframework.view.descriptors.ViewDescriptor;
29
30 import com.iplanet.jato.CompleteRequestException;
31 import com.iplanet.jato.RequestContext;
32 import com.iplanet.jato.RequestManager;
33 import com.iplanet.jato.view.View;
34 import com.iplanet.jato.view.ViewBean;
35
36 import java.util.EventObject JavaDoc;
37
38 import javax.servlet.ServletRequest JavaDoc;
39
40
41 /**
42  * This class provides a means to forward to another Page.
43  */

44 public class NextPageHandler {
45
46     /**
47      * This handler allows you to forward to another View ID. You must
48      * specify the next page's id in a request attribute named "nextPage".
49      */

50     public void forwardTo(RequestContext ctx, HandlerContext handlerCtx) {
51     String JavaDoc nextPage = (String JavaDoc)handlerCtx.getInputValue(NEXT_PAGE);
52     if (nextPage == null) {
53         throw new IllegalArgumentException JavaDoc("The attribute '"+NEXT_PAGE+
54         "' must be set to the ID of the next page to display!");
55     }
56     try {
57         ViewBean viewBean = ctx.getViewBeanManager().getViewBean(nextPage);
58         viewBean.forwardTo(ctx);
59     } catch (ClassNotFoundException JavaDoc ex) {
60         throw new FrameworkException(
61         "Unable to find the ViewBean specified by page id: " +
62         nextPage, ex);
63     }
64     }
65
66     /**
67      * <p> Use this handler to indicate that the Request has been handled.
68      * This is needed if you manually forward to prevent the framework for
69      * attempting to forward again, which would cause a problem. This
70      * handler does not require any parameters.</p>
71      */

72     public void markRequestComplete(RequestContext ctx, HandlerContext handlerCtx) {
73     throw new CompleteRequestException();
74     }
75
76
77
78     //////////////////////////////////////////////////////////////////
79
// Class Variables
80
//////////////////////////////////////////////////////////////////
81

82
83     /**
84      * Request attribute key for the next page
85      */

86     public static final String JavaDoc NEXT_PAGE = "nextPage";
87 }
88
Popular Tags