KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > beehive > netui > tags > databinding > invoke > CallPageFlow


1 /*
2  * Copyright 2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * $Header:$
17  */

18 package org.apache.beehive.netui.tags.databinding.invoke;
19
20 import javax.servlet.http.HttpServletRequest JavaDoc;
21 import javax.servlet.http.HttpServletResponse JavaDoc;
22
23 import org.apache.beehive.netui.pageflow.PageFlowUtils;
24 import org.apache.beehive.netui.pageflow.internal.InternalUtils;
25 import org.apache.beehive.netui.util.Bundle;
26 import org.apache.beehive.netui.util.logging.Logger;
27
28 /**
29  * <p>
30  * Calls methods on the current Page Flow. If no Controller file is found, an
31  * {@link ObjectNotFoundException} is thrown and the tag execution fails.
32  * Any return value is stored in the <code>${pageScope...}</code> data binding context object under the
33  * attribute specified by the <code>resultId</code> attribute.
34  * </p>
35  * <p>
36  * For example, given a <code>hello</code> method and the following &lt;netui-data:callPageFlow> tag:
37  * <pre>
38  * &lt;netui-data:callPageFlow method="hello" resultId="helloMessage"/>
39  * </pre>
40  * <p>
41  * the result of the call is stored in the <code>${pageScope}</code> JSP EL implicit object under
42  * the attribute <code>helloMessage</code>. It will be accessible via <code>${pageScope.helloMessage}</code> and
43  * can be used as:
44  * <pre>
45  * &lt;netui:span value="<b>${pageScope.helloMessage}</b>"/>
46  * </pre>
47  * </p>
48  * <p>
49  * In JSP scriptlet, the result can be retrieved by calling the <code>getAttribute()</code> method on the
50  * {@link javax.servlet.jsp.PageContext javax.servlet.jsp.PageContext} object:
51  * <pre>
52  * &lt;%= pageContext.getAttribute("helloMessage") %>
53  * </pre>
54  * </p>
55  *
56  * @jsptagref.tagdescription
57  * Calls methods on the current Page Flow. If no Controller file is found, an
58  * {@link ObjectNotFoundException} is thrown and the tag execution fails.
59  * Any return value is stored in the <code>${pageScope...}</code> data binding context object under the
60  * attribute specified by the <code>resultId</code> attribute.
61  * <p/>
62  * <p>
63  * For example, given a <code>hello</code> method and the following &lt;netui-data:callPageFlow> tag:
64  * <pre>
65  * &lt;netui-data:callPageFlow method="hello" resultId="helloMessage"/>
66  * </pre>
67  * <p>
68  * the result of the call is stored in the <code>${pageScope}</code> JSP EL implicit object under
69  * the attribute <code>helloMessage</code>. It will be accessible via <code>${pageScope.helloMessage}</code> and
70  * can be used as:
71  * <pre>
72  * &lt;netui:span value="<b>${pageScope.helloMessage}</b>"/>
73  * </pre>
74  * </p>
75  * <p>
76  * In JSP scriptlet, the result can be retrieved by calling the <code>getAttribute()</code> method on the
77  * {@link javax.servlet.jsp.PageContext javax.servlet.jsp.PageContext} object:
78  * <pre>
79  * &lt;%= pageContext.getAttribute("helloMessage") %>
80  * </pre>
81  * </p>
82  * @example
83  * In the following sample, the &lt;netui-data:callPageFlow> tag calls the
84  * sumCartItems method on the Controller file. The {@link org.apache.beehive.netui.tags.html.Span} tag
85  * accesses the result through the ${pageScope} data binding context.
86  * <pre>
87  * &lt;netui-data:callPageFlow method="sumCartItems" resultId="cartSum">
88  * &lt;netui-data:methodParameter value="${pageFlow.cart.lineItemList}"/>
89  * &lt;/netui-data:callPageFlow>
90  * ...
91  * &lt;netui:span value="${pageScope.cartSum}"/>
92  * </pre>
93  * @netui:tag name="callPageFlow" deprecated="true"
94  * description="Use this tag to call a method on the current page flow controller."
95  */

96 public class CallPageFlow
97         extends CallMethod {
98
99     private static final Logger LOGGER = Logger.getInstance(CallPageFlow.class);
100     private static final String JavaDoc DEFAULT_OBJECT_NAME = Bundle.getString("Tags_CallPageFlow_defaultObjectName");
101
102     /**
103      * Get the name of this tag. This is used to identify the type of this tag
104      * for reporting tag errors.
105      *
106      * @return a constant String representing the name of this tag.
107      */

108     public String JavaDoc getTagName() {
109         return "CallPageFlow";
110     }
111
112     /**
113      * Get the name of the object that is the target of the invocation.
114      *
115      * @return a name for the object on which the method will be invoked.
116      */

117     protected String JavaDoc getObjectName() {
118         return DEFAULT_OBJECT_NAME;
119     }
120
121     /**
122      * Get the PageFlow for the using JSP's directory. This is an implementation of the
123      * {@link CallMethod#resolveObject()} method that finds the current PageFlow
124      * using the {@link PageFlowUtils#getCurrentPageFlow} method.
125      *
126      * @return the current PageFlow. If there is no current PageFlow, the {@link ObjectNotFoundException} will
127      * be thrown.
128      * @throws ObjectNotFoundException when an exception occurs ensuring that a Page Flow is created.
129      */

130     protected Object JavaDoc resolveObject()
131             throws ObjectNotFoundException {
132         try {
133             // TODO: because of a javac bug (http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5090006), we
134
// can't call PageFlowUtils.getCurrentPageFlow here; thus, the call to getCurrentActionResolver.
135
Object JavaDoc jpf = PageFlowUtils.getCurrentActionResolver((HttpServletRequest JavaDoc)pageContext.getRequest());
136
137             if(LOGGER.isDebugEnabled())
138                 LOGGER.debug("Found a pageflow of type: " + (jpf != null ? jpf.getClass().getName() : "null"));
139
140             return jpf;
141         }
142         catch(Exception JavaDoc e) {
143             throw new ObjectNotFoundException(Bundle.getErrorString("Tags_CallPageFlow_noPageFlow"), e);
144         }
145     }
146 }
147
Popular Tags