You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 60 Next »

Struts 2.0.0 is the first distribution of WebWork 2 as an Apache Struts product.

  • If you are a Maven user, you might want to get started using the Maven Archetype.
  • Another quick-start entry point is the blank application. Rename and deploy the WAR as a starting point for your own development.

Known Issues

Key Snippets

Maven Artifact ID

<dependency>
  <groupId>org.apache.struts</groupId>
    <artifactId>struts2-core</artifactId>
      <version>2.0.0-SNAPSHOT</version>
</dependency>

Struts Configuration XML

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
  "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
  "http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
    <include file="struts-default.xml"/>
    <package name="support" extends="struts-default">
        <action name="$name" class="$class">
            <result>$location</result>
        </action>
    </package>
</struts>

XWork Validation XML

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE validators PUBLIC 
   "-//OpenSymphony Group//XWork Validator 1.0.2//EN" 
   "http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">
<validators>
    <field name="$name">
        <field-validator type="$type">
            <message>$message</message>
        </field-validator>
    </field>
</validators>

Struts Configuration XML with Wildcards

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
        "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
        "http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
    <include file="struts-default.xml"/>
    <package name="actions" extends="struts-default">
        <global-results>
            <result name="error">/Error.jsp</result>
            <result>{1}/execute.jsp</result>
            <result name="input">{1}/input.jsp</result>
        </global-results>
        <global-exception-mappings>
            <exception-mapping
              result="error" exception="java.lang.Throwable"/>
        </global-exception-mappings>
        <action name="*/*" class="actions.{1}" method="{2}" />
    </package>
</struts>


h2. New Features and Extensions

* [Acegi Security] extension is available.
* [CheckBox Interceptor] detects unchecked checkboxes and adds a parameter with a default value (usually 'false') .  
* [JavaServer Faces|JavaServer Faces] extension is available.
* A {{struts.xml}} file can be placed in a JAR and automatically plugged into an application, so that modules can be self-contained and automatically configured. 
** In the case of Freemarker and Velocity modules, the templates can also be loaded from the classpath, so the entire module can be plugged in as a single JAR.
* (!) Debug Interceptor displays the value stack at runtime.

h2. Key Changes

Depending on whether you are coming from a Struts 1 or a WebWork 2 background, your perspective on the key changes will differ. 

h3. From Struts 1

* See [Comparing Struts 1 and 2]
* (!) More notes to come ...

h3. From WebWork 2 

* Struts 2 is dependant on XWork 2 (nightly build).
* Java 1.5 is required to build and deploy Struts 2. 
** For Java 1.4 deployments, RetroWeaver or RetroTranslater may be used to provide Java 1.4 support
** A pre-packaged set of RetroTranslator JARs is being provided with the distribution.

For other changes from WebWork 2, see the "Members to rename", "New property settings", "New features or feature changes", and "Removed or deprecated".

h4. Members to rename 

||WebWork 2                  || Struts 2             |
|{{com.opensymphony.xwork.*}}  | {{com.opensymphony.xwork2.*}} |
|{{com.opensymphony.webwork.*}} | {{org.apache.struts2.*}}  |
|{{xwork.xml}}               | {{struts.xml}}        |
|{{webwork.properties}}      | {{struts.properties}} |
|DispatcherUtil              | Dispatcher            |
|com.opensymphony.webwork.config.Configuration|org.apache.struts2.config.Settings|

The tag prefix conventions in the example applications have changed. 

||JSP        | s: | _<s:form ...>_ |
||Freemarker | s. | _<@s.form ...>_ | 
||Velocity   | s  | _#sform ( ... )_ | 

h4. New property settings 

||struts.enable.DynamicMethodInvocation | Enable support for the hardwired {{action!alias}} syntax (Default is {{TRUE}})|  

{tip}It is recommended that all applications specify the DynamicMethodInvocation setting for now, since the default may change. The recommended approach to action aliasing is to use [wildcard aliases|Action Configuration#Wildcard Aliases] instead of the hardwired bang.{tip}

h4. New features and feature changes

* Various changes to ConfigurationManager
** ConfigurationManager is no longer a static factory. It is now an instance created through Dispatcher. Custom configuration could be done through DispatcherListener.
** Custom configuration to ConfigurationManager and Configuration cannot be done statically anymore, instead use Dispatcher's DispatcherListener to achieve the same effect.
* The {{prepare}} interceptor now uses reflection to call prepare_Method_ where _method_ is the action method configured for the particular action in {{struts.xml}}.

<action name="myAction" method="insert" ....>
.....
</action>

// with the above configuration, and PrepareInterceptor in play,
// callsequence will be
1] prepareInsert() (If it exists)
2] prepare() (Unless Interceptor's alwaysInvokePrepare parameter is set to false)
3] insert()

* DefaultWorkflowInterceptor (named {{workflow}} in {{struts-default.xml}}) now uses reflection to call {{validateMethod}} on the action class that implements Validateable interface where {{method}} is the action method configured for the particular action in {{struts.xml}}.

<action name="myAction" method="insert" ...>
...
</action>

// with the above configuration, and DefaultWorkflowInterceptor in play,
// call sequence for action that implements Validateable interface will be
1] validateInsert()
2] validate() (unless Interceptor's alwaysInvokeValidate parameter is set to false)
3] insert()

* Datepicker tag is now using dojo's (limited in terms functionality and internationalization) 
* [Tiles integration|Tiles] extension is available.
* [Wildcards|Action Configuration#Wildcard Aliases] can be specified in action mappings.
* [MessageStoreInterceptor|Message Store Interceptor] is introduced to allow field errors / action errors and messages to be store and retrieve through session, resulting them to be preservable across request.


h4. Removed or deprecated

||AroundInterceptor| The AroundInterceptor has been removed. If your application extends the AroundInterceptor, either import the class into your source code form WebWork 2 (pursuant to the Open Symphony License) and modify it to server as your own base class, or rewrite your interceptor. |
||{{oldSyntax}}| Support for the "oldSyntax" is removed. | 
|| Rich text editor tag | Rich text editor tag has been removed (a possible replacement would be to use the textarea tag with theme="ajax", this will used dojo's rich text editor) 

<s:textarea theme="ajax" />

 |
|| {{doActionMethod}} | The convention of trying a "do" form of an action method is not supported. 

<action name="..." method="submit">
...
</action>

 

In WebWork,

  • try to execute submit method in the action, fail
  • try to execute doSubmit method in the action if Step 1, fail
  • fail
    In Struts,
  • try to execute submit method in the action, fail
  • fail

    default method

    Calling the "default" method via "doDefault" is not supported.

Detail

Pending and open issues

type key summary status resolution

Data cannot be retrieved due to an unexpected error.

View these issues in Jira

Other resources

  • No labels