001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: * $Header:$
018: */
019: package org.apache.beehive.netui.tags.databinding.invoke;
020:
021: import javax.servlet.http.HttpServletRequest;
022: import javax.servlet.http.HttpServletResponse;
023:
024: import org.apache.beehive.netui.pageflow.PageFlowUtils;
025: import org.apache.beehive.netui.pageflow.internal.InternalUtils;
026: import org.apache.beehive.netui.util.Bundle;
027: import org.apache.beehive.netui.util.logging.Logger;
028:
029: /**
030: * <p>
031: * Calls methods on the current Page Flow. If no Controller file is found, an
032: * {@link ObjectNotFoundException} is thrown and the tag execution fails.
033: * Any return value is stored in the <code>${pageScope...}</code> data binding context object under the
034: * attribute specified by the <code>resultId</code> attribute.
035: * </p>
036: * <p>
037: * For example, given a <code>hello</code> method and the following <netui-data:callPageFlow> tag:
038: * <pre>
039: * <netui-data:callPageFlow method="hello" resultId="helloMessage"/>
040: * </pre>
041: * <p>
042: * the result of the call is stored in the <code>${pageScope}</code> JSP EL implicit object under
043: * the attribute <code>helloMessage</code>. It will be accessible via <code>${pageScope.helloMessage}</code> and
044: * can be used as:
045: * <pre>
046: * <netui:span value="<b>${pageScope.helloMessage}</b>"/>
047: * </pre>
048: * </p>
049: * <p>
050: * In JSP scriptlet, the result can be retrieved by calling the <code>getAttribute()</code> method on the
051: * {@link javax.servlet.jsp.PageContext javax.servlet.jsp.PageContext} object:
052: * <pre>
053: * <%= pageContext.getAttribute("helloMessage") %>
054: * </pre>
055: * </p>
056: *
057: * @jsptagref.tagdescription
058: * Calls methods on the current Page Flow. If no Controller file is found, an
059: * {@link ObjectNotFoundException} is thrown and the tag execution fails.
060: * Any return value is stored in the <code>${pageScope...}</code> data binding context object under the
061: * attribute specified by the <code>resultId</code> attribute.
062: * <p/>
063: * <p>
064: * For example, given a <code>hello</code> method and the following <netui-data:callPageFlow> tag:
065: * <pre>
066: * <netui-data:callPageFlow method="hello" resultId="helloMessage"/>
067: * </pre>
068: * <p>
069: * the result of the call is stored in the <code>${pageScope}</code> JSP EL implicit object under
070: * the attribute <code>helloMessage</code>. It will be accessible via <code>${pageScope.helloMessage}</code> and
071: * can be used as:
072: * <pre>
073: * <netui:span value="<b>${pageScope.helloMessage}</b>"/>
074: * </pre>
075: * </p>
076: * <p>
077: * In JSP scriptlet, the result can be retrieved by calling the <code>getAttribute()</code> method on the
078: * {@link javax.servlet.jsp.PageContext javax.servlet.jsp.PageContext} object:
079: * <pre>
080: * <%= pageContext.getAttribute("helloMessage") %>
081: * </pre>
082: * </p>
083: * @example
084: * In the following sample, the <netui-data:callPageFlow> tag calls the
085: * sumCartItems method on the Controller file. The {@link org.apache.beehive.netui.tags.html.Span} tag
086: * accesses the result through the ${pageScope} data binding context.
087: * <pre>
088: * <netui-data:callPageFlow method="sumCartItems" resultId="cartSum">
089: * <netui-data:methodParameter value="${pageFlow.cart.lineItemList}"/>
090: * </netui-data:callPageFlow>
091: * ...
092: * <netui:span value="${pageScope.cartSum}"/>
093: * </pre>
094: * @netui:tag name="callPageFlow" deprecated="true"
095: * description="Use this tag to call a method on the current page flow controller."
096: */
097: public class CallPageFlow extends CallMethod {
098:
099: private static final Logger LOGGER = Logger
100: .getInstance(CallPageFlow.class);
101: private static final String DEFAULT_OBJECT_NAME = Bundle
102: .getString("Tags_CallPageFlow_defaultObjectName");
103:
104: /**
105: * Get the name of this tag. This is used to identify the type of this tag
106: * for reporting tag errors.
107: *
108: * @return a constant String representing the name of this tag.
109: */
110: public String getTagName() {
111: return "CallPageFlow";
112: }
113:
114: /**
115: * Get the name of the object that is the target of the invocation.
116: *
117: * @return a name for the object on which the method will be invoked.
118: */
119: protected String getObjectName() {
120: return DEFAULT_OBJECT_NAME;
121: }
122:
123: /**
124: * Get the PageFlow for the using JSP's directory. This is an implementation of the
125: * {@link CallMethod#resolveObject()} method that finds the current PageFlow
126: * using the {@link PageFlowUtils#getCurrentPageFlow} method.
127: *
128: * @return the current PageFlow. If there is no current PageFlow, the {@link ObjectNotFoundException} will
129: * be thrown.
130: * @throws ObjectNotFoundException when an exception occurs ensuring that a Page Flow is created.
131: */
132: protected Object resolveObject() throws ObjectNotFoundException {
133: try {
134: /* todo: because of a javac bug (http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5090006), we
135: can't call PageFlowUtils.getCurrentPageFlow here; thus, the call to getCurrentActionResolver.
136: */
137: Object jpf = PageFlowUtils.getCurrentPageFlow(
138: (HttpServletRequest) pageContext.getRequest(),
139: pageContext.getServletContext());
140:
141: if (LOGGER.isDebugEnabled())
142: LOGGER.debug("Found a pageflow of type: "
143: + (jpf != null ? jpf.getClass().getName()
144: : "null"));
145:
146: return jpf;
147: } catch (Exception e) {
148: throw new ObjectNotFoundException(Bundle
149: .getErrorString("Tags_CallPageFlow_noPageFlow"), e);
150: }
151: }
152: }
|