From bc2fdd50fdb7062b67db6446d89fd4e29864dfb8 Mon Sep 17 00:00:00 2001 From: Ted Nathan Husted Date: Fri, 1 Sep 2006 00:00:52 +0000 Subject: [PATCH] WW-1392 Restore TLD and snippet code from prior revisions, since we are going to try using XDoclet with J5 instead. git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@439109 13f79535-47bb-0310-9956-ffa450edef68 --- .../struts2/components/ActionComponent.java | 243 ++++++++++-------- .../struts2/components/ActionError.java | 42 +-- .../main/resources/META-INF/struts-tags.tld | 227 ++++++++-------- 3 files changed, 284 insertions(+), 228 deletions(-) diff --git a/core/src/main/java/org/apache/struts2/components/ActionComponent.java b/core/src/main/java/org/apache/struts2/components/ActionComponent.java index 336ee0dae..ac87e4780 100644 --- a/core/src/main/java/org/apache/struts2/components/ActionComponent.java +++ b/core/src/main/java/org/apache/struts2/components/ActionComponent.java @@ -17,6 +17,11 @@ */ package org.apache.struts2.components; +import org.apache.struts2.ServletActionContext; +import org.apache.struts2.StrutsException; +import org.apache.struts2.dispatcher.Dispatcher; +import org.apache.struts2.dispatcher.RequestMap; +import org.apache.struts2.views.jsp.TagUtils; import com.opensymphony.xwork2.ActionContext; import com.opensymphony.xwork2.ActionProxy; import com.opensymphony.xwork2.ActionProxyFactory; @@ -24,107 +29,123 @@ import com.opensymphony.xwork2.config.Configuration; import com.opensymphony.xwork2.util.OgnlValueStack; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.struts2.ServletActionContext; -import org.apache.struts2.StrutsConstants; -import org.apache.struts2.StrutsException; -import org.apache.struts2.config.Settings; -import org.apache.struts2.dispatcher.Dispatcher; -import org.apache.struts2.dispatcher.RequestMap; -import org.apache.struts2.views.jsp.TagUtils; import javax.servlet.ServletContext; +import javax.servlet.jsp.PageContext; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import javax.servlet.jsp.PageContext; + import java.io.IOException; import java.io.Writer; import java.util.HashMap; import java.util.Map; /** - * Invoke an action directly from a view. - * See struts-tags.tld for documentation. + * + *

This tag enables developers to call actions directly from a JSP page by specifying the action name and an optional + * namespace. The body content of the tag is used to render the results from the Action. Any result processor defined + * for this action in struts.xml will be ignored, unless the executeResult parameter is specified.

+ * + * + * + * + * + * + *
+ * 
+ * public class ActionTagAction extends ActionSupport {
+ *
+ *	public String execute() throws Exception {
+ *		return "done";
+ *	}
+ *
+ *	public String doDefault() throws Exception {
+ *		ServletActionContext.getRequest().setAttribute("stringByAction", "This is a String put in by the action's doDefault()");
+ *		return "done";
+ *	}
+ * }
+ * 
+ * 
+ * + *
+ * 
+ *   
+ *      ....
+ *     
+ *         success.jsp
+ *     
+ *      
+ *         success.jsp
+ *     
+ *      ....
+ *   
+ * 
+ * 
+ * + *
+ * 
+ *  
The following action tag will execute result and include it in this page
+ *
+ * + *
+ *
The following action tag will do the same as above, but invokes method specialMethod in action
+ *
+ * + *
+ *
The following action tag will not execute result, but put a String in request scope + * under an id "stringByAction" which will be retrieved using property tag
+ * + * + * + *
+ * + * @s.tag name="action" tld-body-content="JSP" tld-tag-class="org.apache.struts2.views.jsp.ActionTag" + * description="Execute an action from within a view" */ public class ActionComponent extends Component { private static final Log LOG = LogFactory.getLog(ActionComponent.class); - /** - * Store our HttpServletResponse. - */ - protected HttpServletResponse response; + protected HttpServletResponse res; + protected HttpServletRequest req; - /** - * Store our HttpServletRequest. - */ - protected HttpServletRequest request; - - /** - * Store our ActionProxy. - */ protected ActionProxy proxy; - - /** - * Store the action mapping name. - */ protected String name; - - /** - * Store the action mappinng namespace, if different. - */ protected String namespace; - - /** - * Indicate whether to invoke the result class and render its content. - */ protected boolean executeResult; - - /** - * Indicate whether to pass the request parameters to the Action invocation. - */ protected boolean ignoreContextParams; - /** - * Construct object instance, setting runtime parameters. - * - * @param stack Our OgnlValueStack - * @param request Our HttpServletRequest - * @param response Our HttpServletResponse - */ - public ActionComponent(OgnlValueStack stack, HttpServletRequest request, HttpServletResponse response) { + public ActionComponent(OgnlValueStack stack, HttpServletRequest req, HttpServletResponse res) { super(stack); - this.request = request; - this.response = response; + this.req = req; + this.res = res; } - - // See superclass for documentation public boolean end(Writer writer, String body) { - boolean end = super.end(writer, "", false); - try { - try { - writer.flush(); - } catch (IOException e) { - LOG.warn("error while trying to flush writer ", e); - } - executeAction(); + boolean end = super.end(writer, "", false); + try { + try { + writer.flush(); + } catch (IOException e) { + LOG.warn("error while trying to flush writer ", e); + } + executeAction(); - if ((getId() != null) && (proxy != null)) { - getStack().setValue("#attr['" + getId() + "']", - proxy.getAction()); - } - } finally { - popComponentStack(); - } + if ((getId() != null) && (proxy != null)) { + getStack().setValue("#attr['" + getId() + "']", + proxy.getAction()); + } + } finally { + popComponentStack(); + } return end; } - /** - * Create a context in which to invoke Action class, - * passing along context parameters - * if ignoreContextParams is FALSE. - * - * @return A map representing the new context - */ private Map createExtraContext() { Map parentParams = null; @@ -145,12 +166,12 @@ public class ActionComponent extends Component { Map application = ctx.getApplication(); Dispatcher du = Dispatcher.getInstance(); - Map extraContext = du.createContextMap(new RequestMap(request), + Map extraContext = du.createContextMap(new RequestMap(req), newParams, session, application, - request, - response, + req, + res, servletContext); OgnlValueStack newStack = new OgnlValueStack(stack); @@ -162,37 +183,42 @@ public class ActionComponent extends Component { return extraContext; } + public ActionProxy getProxy() { + return proxy; + } + /** - * Invoke the Action class, - * If no namespace is provided, attempt to derive a namespace using the buildNamespace method. + * Execute the requested action. If no namespace is provided, we'll + * attempt to derive a namespace using buildNamespace(). The ActionProxy + * and the namespace will be saved into the instance variables proxy and + * namespace respectively. * * @see org.apache.struts2.views.jsp.TagUtils#buildNamespace */ private void executeAction() { - // FIXME: our implementation is flawed - the only concept of ! should be in DefaultActionMapper - boolean allowDynamicMethodCalls = "true".equals(Settings.get(StrutsConstants.STRUTS_ENABLE_DYNAMIC_METHOD_INVOCATION)); String actualName = findString(name, "name", "Action name is required. Example: updatePerson"); if (actualName == null) { throw new StrutsException("Unable to find value for name " + name); } - String actionName = actualName; - String methodName = null; - // handle "name!method" convention. - if (allowDynamicMethodCalls) { - int exclamation = actualName.lastIndexOf("!"); - if (exclamation != -1) { - actionName = actualName.substring(0, exclamation); - methodName = actualName.substring(exclamation + 1); - } + final String actionName; + final String methodName; + + int exclamation = actualName.lastIndexOf("!"); + if (exclamation != -1) { + actionName = actualName.substring(0, exclamation); + methodName = actualName.substring(exclamation + 1); + } else { + actionName = actualName; + methodName = null; } String namespace; if (this.namespace == null) { - namespace = TagUtils.buildNamespace(getStack(), request); + namespace = TagUtils.buildNamespace(getStack(), req); } else { namespace = findString(this.namespace); } @@ -202,21 +228,20 @@ public class ActionComponent extends Component { // execute at this point, after params have been set try { Configuration config = Dispatcher.getInstance().getConfigurationManager().getConfiguration(); - proxy = ActionProxyFactory.getFactory().createActionProxy(config, namespace, actionName, - createExtraContext(), executeResult, true); + proxy = ActionProxyFactory.getFactory().createActionProxy(config, namespace, actionName, createExtraContext(), executeResult, true); if (null != methodName) { proxy.setMethod(methodName); } // set the new stack into the request for the taglib to use - request.setAttribute(ServletActionContext.STRUTS_VALUESTACK_KEY, proxy.getInvocation().getStack()); + req.setAttribute(ServletActionContext.STRUTS_VALUESTACK_KEY, proxy.getInvocation().getStack()); proxy.execute(); } catch (Exception e) { - String message = "Could not invoke action: " + namespace + "/" + actualName; + String message = "Could not execute action: " + namespace + "/" + actualName; LOG.error(message, e); } finally { // set the old stack back on the request - request.setAttribute(ServletActionContext.STRUTS_VALUESTACK_KEY, stack); + req.setAttribute(ServletActionContext.STRUTS_VALUESTACK_KEY, stack); } if ((getId() != null) && (proxy != null)) { @@ -226,35 +251,41 @@ public class ActionComponent extends Component { } /** - * Expose proxy instance (for testing). - * - * @return proxy instance + * the id (if speficied) to put the action under stack's context. + * @s.tagattribute required="false" type="String" */ - public ActionProxy getProxy() { - return proxy; - } - - // See TLD for documentation public void setId(String id) { super.setId(id); } - // See TLD for documentation + /** + * name of the action to be executed (without the extension suffix eg. .action) + * @s.tagattribute required="true" type="String" + */ public void setName(String name) { this.name = name; } - // See TLD for documentation + /** + * namespace for action to call + * @s.tagattribute required="false" type="String" default="namespace from where tag is used" + */ public void setNamespace(String namespace) { this.namespace = namespace; } - // See TLD for documentation + /** + * whether the result of this action (probably a view) should be executed/rendered + * @s.tagattribute required="false" type="Boolean" default="false" + */ public void setExecuteResult(boolean executeResult) { this.executeResult = executeResult; } - // See TLD for documentation + /** + * whether the request parameters are to be included when the action is invoked + * @s.tagattribute required="false" type="Boolean" default="false" + */ public void setIgnoreContextParams(boolean ignoreContextParams) { this.ignoreContextParams = ignoreContextParams; } diff --git a/core/src/main/java/org/apache/struts2/components/ActionError.java b/core/src/main/java/org/apache/struts2/components/ActionError.java index 7fd9b0b7e..b5ac53b1c 100644 --- a/core/src/main/java/org/apache/struts2/components/ActionError.java +++ b/core/src/main/java/org/apache/struts2/components/ActionError.java @@ -23,32 +23,38 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; /** - * Render action errors, if they exist, - * obtaining the layout from theme. + * + * + * Render action errors if they exists the specific layout of the rendering depends on + * the theme itself. + * + * + * + *

Examples + * + *

+ * 
+ *
+ *    <s:actionerror />
+ *    <s:form .... >>
+ *       ....
+ *    </s:form>
+ *
+ * 
+ * 
+ * + * @s.tag name="actionerror" tld-body-content="empty" tld-tag-class="org.apache.struts2.views.jsp.ui.ActionErrorTag" + * description="Render action errors if they exists" */ public class ActionError extends UIBean { - /** - * Provide the tag template name. - */ - private static final String TEMPLATE = "actionerror"; + public static final String TEMPLATE = "actionerror"; + - /** - * Construct object instance, setting runtime parameters. - * - * @param stack Our OgnlValueStack - * @param request Our HttpServletRequest - * @param response Our HttpServletResponse - */ public ActionError(OgnlValueStack stack, HttpServletRequest request, HttpServletResponse response) { super(stack, request, response); } - /** - * Provide the tag's default template. - * - * @return the tag's default template - */ protected String getDefaultTemplate() { return TEMPLATE; } diff --git a/core/src/main/resources/META-INF/struts-tags.tld b/core/src/main/resources/META-INF/struts-tags.tld index ac99c03c1..44bee5a44 100644 --- a/core/src/main/resources/META-INF/struts-tags.tld +++ b/core/src/main/resources/META-INF/struts-tags.tld @@ -13,8 +13,7 @@ @@ -3005,87 +3004,51 @@ action org.apache.struts2.views.jsp.ActionTag JSP - - Invoke an action directly from a view. - Tag attributes specify an action name and an optional namespace. - Tag body content renders the result from the Action. - If the executeResult attribute is TRUE, - any result class specified by the action mapping is invoked and rendered, - otherwise the result is ignored. - + + id false true - If specified, the action's stack context ID + + + name true true - Action mapping to invoke + + + + namespace false true - The action mapping's namespace (if different than the current namespace) + + + executeResult false true - If TRUE, invoke the result class, rendering its content (if any) + + + + ignoreContextParams false true - If FALSE, include the request parameters during the action invocation + + + + - - - .... - - success.jsp - - - success.jsp - - .... - - - -
-

- Content rendered by another Action, invoked as this page is being rendered: -

- -
-

- Content placed into the context by another Action, invoked as this page is being rendered: -

- - -

- (Note that the Action itself did not render a result.) -

- ]]> @@ -3523,219 +3486,275 @@ public class ActionTagAction extends ActionSupport { actionerror org.apache.struts2.views.jsp.ui.ActionErrorTag empty - - Render action errors, if they exist, obtaining the layout from theme. - + + theme false true - Theme (other than default) to use for rendering the element + + + templateDir false true - Template directory (other than default) to use to find the themes (and hence the template) + + + + template false true - Template (other than default) to use for rendering the element + + + cssClass false true - Cascading Style Sheet class (other than default)for element to use + + + cssStyle false true - Cascading Style Sheet definitions for element to use + + + title false true - HTML title attribute for element to use + + + disabled false true - HTML disabled attribute for element to use + + + label false true - Label expression used for rendering a element specific label + + + labelPosition false true + + labelposition false true - Label position for form element (top/left) + + + requiredposition false true - Required position for form element (left|right) + + + name false true - Name for element + + + required false true + - If TRUE, rendered element will indicate that input is required. - + + tabindex false true - HTML tabindex attribute for rendered HTML element + + + value false true - Preset value of input element + + + onclick false true - HTML attribute for rendered element + + + ondblclick false true - HTML attribute for rendered element + + + onmousedown false true - HTML attribute for rendered element + + + onmouseup false true - HTML attribute for rendered element + + + onmouseover false true - HTML attribute for rendered element + + + onmousemove false true - HTML attribute for rendered element + + + onmouseout false true - HTML attribute for rendered element + + + onfocus false true - HTML attribute for rendered element + + + onblur false true - HTML attribute for rendered element + + + onkeypress false true - HTML attribute for rendered element + + + onkeydown false true - HTML attribute for rendered element + + + onkeyup false true - HTML attribute for rendered element + + + onselect false true - HTML attribute for rendered element + + + onchange false true - HTML attribute for rendered element + + + accesskey false true - HTML attribute for rendered element + + + tooltip false true - Tooltip attribute for rendered element + + + tooltipConfig false true - TooltipConfig attribute for rendered element + + + id false true + - Unique id for referencing element. - For UI and form tags it will be used as HTML id attribute - + + - - -... - - ]]> @@ -3743,7 +3762,7 @@ public class ActionTagAction extends ActionSupport { if org.apache.struts2.views.jsp.IfTag JSP - If tag + test