org.apache.struts2.components
Class ActionComponent

java.lang.Object
  extended by org.apache.struts2.components.Component
      extended by org.apache.struts2.components.ActionComponent

public class ActionComponent
extends Component

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


Field Summary
protected  ActionProxyFactory actionProxyFactory
           
protected  boolean executeResult
           
protected  boolean flush
           
protected  boolean ignoreContextParams
           
private static Log LOG
           
protected  String name
           
protected  String namespace
           
protected  ActionProxy proxy
           
protected  HttpServletRequest req
           
protected  HttpServletResponse res
           
 
Fields inherited from class org.apache.struts2.components.Component
actionMapper, COMPONENT_STACK, id, parameters, stack
 
Constructor Summary
ActionComponent(ValueStack stack, HttpServletRequest req, HttpServletResponse res)
           
 
Method Summary
private  Map createExtraContext()
           
 boolean end(Writer writer, String body)
          Callback for the end tag of this component.
private  void executeAction()
          Execute the requested action.
 ActionProxy getProxy()
           
 void setActionProxyFactory(ActionProxyFactory actionProxyFactory)
           
 void setExecuteResult(boolean executeResult)
           
 void setFlush(boolean flush)
           
 void setIgnoreContextParams(boolean ignoreContextParams)
           
 void setName(String name)
           
 void setNamespace(String namespace)
           
 
Methods inherited from class org.apache.struts2.components.Component
addAllParameters, addParameter, altSyntax, copyParams, determineActionURL, determineActionURL, determineNamespace, end, fieldError, findAncestor, findString, findString, findValue, findValue, findValue, getComponentStack, getId, getParameters, getStack, popComponentStack, setActionMapper, setId, start, toString, usesBody
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOG

private static final Log LOG

res

protected HttpServletResponse res

req

protected HttpServletRequest req

actionProxyFactory

protected ActionProxyFactory actionProxyFactory

proxy

protected ActionProxy proxy

name

protected String name

namespace

protected String namespace

executeResult

protected boolean executeResult

ignoreContextParams

protected boolean ignoreContextParams

flush

protected boolean flush
Constructor Detail

ActionComponent

public ActionComponent(ValueStack stack,
                       HttpServletRequest req,
                       HttpServletResponse res)
Method Detail

setActionProxyFactory

public void setActionProxyFactory(ActionProxyFactory actionProxyFactory)
Parameters:
actionProxyFactory - the actionProxyFactory to set

end

public boolean end(Writer writer,
                   String body)
Description copied from class: Component
Callback for the end tag of this component. Should the body be evaluated again?

NOTE: will pop component stack.

Overrides:
end in class Component
Parameters:
writer - the output writer.
body - the rendered body.
Returns:
true if the body should be evaluated again

createExtraContext

private Map createExtraContext()

getProxy

public ActionProxy getProxy()

executeAction

private void executeAction()
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 Also:
TagUtils.buildNamespace(org.apache.struts2.dispatcher.mapper.ActionMapper, com.opensymphony.xwork2.util.ValueStack, javax.servlet.http.HttpServletRequest)

setName

public void setName(String name)

setNamespace

public void setNamespace(String namespace)

setExecuteResult

public void setExecuteResult(boolean executeResult)

setIgnoreContextParams

public void setIgnoreContextParams(boolean ignoreContextParams)

setFlush

public void setFlush(boolean flush)


Copyright © 2000-2008 Apache Software Foundation. All Rights Reserved.