'xwork'에 해당되는 글 1건

  1. 2010.03.11 xwork configuration

xwork configuration

ITWeb/개발일반 2010.03.11 22:32
원본글 : http://wiki.opensymphony.com/display/XW/Configuring+XWork+in+xwork.xml
원본글 :

Attribute Required Description
name yes key to for other packages to reference
extends no inherits package behavior of the package it extends
namespace no see Namespace Configuration
abstract no declares package to be abstract (no action configurations required in package)

<package name="default">
    <action name="foo" class="mypackage.simpleAction>
        <result name="success" type="dispatcher">greeting.jsp</result>
    <action name="bar" class="mypackage.simpleAction">
        <result name="success" type="dispatcher">bar1.jsp</result>

<package name="mypackage1" namespace="/">
    <action name="moo" class="mypackage.simpleActtion">
        <result name="success" type="dispatcher">moo.jsp</result>

<package name="mypackage2" namespace="/barspace">
    <action name="bar" class="mypackage.simpleAction">
        <result name="success" type="dispatcher">bar2.jsp</result>

    <include file="xwork-default.xml"/>
    <include file="xwork-extension.xml"/>
    <include file="xwork-mail.xml"/>
    <include file="xwork-xmlrpc.xml"/>


Actions are the basic "unit-of-work" in XWork, they define, well, actions. An action will usually be a request, (and usually a button click, or form submit). The main action element has two parts, the friendly name (referenced in the URL, i.e. saveForm.action) and the corresponding "handler" class.

<action name="formTest" class="com.opensymphony.xwork.example.SampleAction" method="processSample">

The optional "method" parameter tells XWork which method to call based upon this action. If you leave the method parameter blank, XWork will call the method execute() by default. If there is no execute() method and no method specified in the xml file, XWork will throw an exception.

<package name="myPackage" ....>


<default-action-ref name="simpleViewResultAction">

An example of a default action that is just a simple class
that has 3 fields: successUrl, errorUrl, and inputUrl.  This action
parses the request url to set the result values.  In the normal case
it just renders velocity results of the same name as the requested url.
<action name="simpleViewResultAction" class="SimpleViewResultAction">
<result type="velocity">${successUrl}</result>
<result name="error" type="velocity">${errorUrl}</result>
<result name="input" type="velocity">${inputUrl}</result>



Result tags tell XWork what to do next after the action has been called. There are a standard set of result codes built-in to XWork, (in the Action interface) they include:

String SUCCESS = "success";
String NONE    = "none";
String ERROR   = "error";
String INPUT   = "input";
String LOGIN   = "login";

You can extend these as you see fit. Most of the time you will have either SUCCESS or ERROR, with SUCCESS moving on to the next page in your application;

<result name="success" type="dispatcher">
    <param name="location">/thank_you.jsp</param>

...and ERROR moving on to an error page, or the preceding page;

<result name="error" type="dispatcher">
    <param name="location">/error.jsp</param>

Results are specified in a xwork xml config file (xwork.xml) nested inside <action>. If the location param is the only param being specified in the result tag, you can simplify it as follows:

<action name="bar" class="myPackage.barAction">
  <result name="success" type="dispatcher">
    <param name="location">foo.jsp</param>

or simplified

<action name="bar" class="myPackage.barAction">
  <result name="success" type="dispatcher">foo.jsp</result>

or even simplified further

<action name="bar" class="myPackage.barAction">


    <result-type name="dispatcher" class="com.opensymphony.webwork.dispatcher.ServletDispatcherResult" default="true"/>
    <result-type name="redirect" class="com.opensymphony.webwork.dispatcher.ServletRedirectResult"/>
    <result-type name="velocity" class="com.opensymphony.webwork.dispatcher.VelocityResult"/>
    <result-type name="chain" class="com.opensymphony.xwork.ActionChainResult"/>
    <result-type name="xslt" class="com.opensymphony.webwork.views.xslt.XSLTResult"/>
    <result-type name="jasper" class="com.opensymphony.webwork.views.jasperreports.JasperReportsResult"/>
    <result-type name="freemarker" class="com.opensymphony.webwork.views.freemarker.FreemarkerResult"/>
    <result-type name="httpheader" class="com.opensymphony.webwork.dispatcher.HttpHeaderResult"/>
    <result-type name="stream" class="com.opensymphony.webwork.dispatcher.StreamResult"/>
    <result-type name="plaintext" class="com.opensymphony.webwork.dispatcher.PlainTextResult" />

Result Types

Webwork provides several implementations of the com.opensymphony.xwork.Result interface to make web-based interactions with your actions simple. These result types include:

Intercepters must first be defined (to give name them) and can be chained together as a stack:
  <interceptor name="security" class="com.mycompany.security.SecurityInterceptor"/>
  <interceptor-stack name="defaultComponentStack">
    <interceptor-ref name="component"/>
    <interceptor-ref name="defaultStack"/>

To use them in your actions:

<action name="VelocityCounter" class="com.opensymphony.xwork.example.counter.SimpleCounter">
   <result name="success">...</result>
   <interceptor-ref name="defaultComponentStack"/>


tags : ,
Trackback 0 : Comment 0