Issue Details (XML | Word | Printable)

Key: XW-603
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Rainer Hermanns
Reporter: sutter2k
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
XWork

default-class-ref should be able to be overriden for child packages

Created: 15/Jan/08 01:38 PM   Updated: 02/Mar/08 07:43 AM
Component/s: Configuration
Affects Version/s: 2.0.5, 2.1, 2.1.1
Fix Version/s: 2.1.1

File Attachments: 1. Text File xwork-src.patch (4 kB)
2. Text File xwork-test.patch (4 kB)


Flags: Important, Patch


 Description  « Hide
Currently default-class-ref defined in parent packages sticks to actions despite having default-class-ref defined in sub packages. This is inconsistent behavior to how an default interceptor stacks and be redefined for child packages.

The current behavior also takes away a lot of flexibility that could be achieved via templating out abstract pattern packages.

Given a configuration & test that looks like:
<xwork>
....
<package name="Abstract-crud" extends="default">
   <!-- edit is often used as the create/view -->
   <default-class-ref class="com.opensymphony.xwork2.SimpleAction"/>
                <action name="edit" >
                        <result name="input" type="mock">edit.vm</result>
                        <result name="success" type="mock">edit.vm</result>
                        <result name="error" type="mock">edit.vm</result>
                </action>
                <action name="save" >
                        <result name="input" type="mock">edit.vm</result>
                        <result name="success" type="chain">list</result>
                        <result name="error" type="mock">edit.vm</result>
                        <result name="cancel" type="mock">list.action</result>
                </action>
                <action name="list">
                        <result name="success" type="mock">list</result>
                </action>
                <action name="delete">
                        <result name="success" type="mock">list</result>
                </action>

        </package>
       
        <package name="Example" extends="Abstract-crud" namespace="/example">
                 <default-class-ref class="com.opensymphony.xwork2.ModelDrivenAction" />
        </package>

        <package name="Example2" extends="Abstract-crud" namespace="/example2">
                <default-class-ref class="com.opensymphony.xwork2.ModelDrivenAction" />
                <action name="override">
                        <result name="success" type="mock">somethingelse.vm</result>
                </action>
        </package>

        <package name="SubItem" extends="Abstract-crud" namespace="/example2/subItem">
                <default-class-ref class="com.opensymphony.xwork2.ModelDrivenAction" />
        </package>
        
        <package name="Example3" extends="Abstract-crud" namespace="/example3">
  <!-- default-class-ref is expected to be inherited -->
        </package>

----
</xwork>



public void testDefaultClassDefEvaluation() throws Exception {
        ActionProxy proxy = actionProxyFactory.createActionProxy("Abstract-crud", "edit", null);
        System.out.println(proxy.getConfig().getClassName());
        assertEquals("com.opensymphony.xwork2.SimpleAction", proxy.getConfig().getClassName());
        
        proxy = actionProxyFactory.createActionProxy("/example", "edit", null);
        assertEquals("com.opensymphony.xwork2.ModelDrivenAction", proxy.getConfig().getClassName());
        System.out.println(proxy.getConfig().getClassName());
         

        proxy = actionProxyFactory.createActionProxy("/example2", "override", null);
        assertEquals("com.opensymphony.xwork2.ModelDrivenAction", proxy.getConfig().getClassName());
        System.out.println(proxy.getConfig().getClassName());
        
        proxy = actionProxyFactory.createActionProxy("/example2/subItem", "save", null);
        assertEquals("com.opensymphony.xwork2.ModelDrivenAction", proxy.getConfig().getClassName());
        System.out.println(proxy.getConfig().getClassName());
        
        proxy = actionProxyFactory.createActionProxy("/example2", "list", null);
        assertEquals("com.opensymphony.xwork2.ModelDrivenAction", proxy.getConfig().getClassName());
        System.out.println(proxy.getConfig().getClassName());
        
        proxy = actionProxyFactory.createActionProxy("/example3", "list", null);
        assertEquals("com.opensymphony.xwork2.SimpleAction", proxy.getConfig().getClassName());
        System.out.println(proxy.getConfig().getClassName());
        
    }

The following test should print -->
com.opensymphony.xwork2.SimpleAction
com.opensymphony.xwork2.ModelDrivenAction
com.opensymphony.xwork2.ModelDrivenAction
com.opensymphony.xwork2.ModelDrivenAction
com.opensymphony.xwork2.ModelDrivenAction
com.opensymphony.xwork2.SimpleAction

However, currently xwork prints:

com.opensymphony.xwork2.SimpleAction (correct)
com.opensymphony.xwork2.SimpleAction (incorrect)
com.opensymphony.xwork2.ModelDrivenAction (correct)
com.opensymphony.xwork2.SimpleAction (incorrect)
com.opensymphony.xwork2.SimpleAction (incorrect)
com.opensymphony.xwork2.SimpleAction (correct)



 All   Comments   Change History      Sort Order: Ascending order - Click to sort in descending order
sutter2k added a comment - 15/Jan/08 01:41 PM
patch for tests .

Adds test defs to xwork-sample.xml and creates DefaultClassTest.java

sutter2k added a comment - 15/Jan/08 01:46 PM
patch to xwork src/java

Basically, if no class is given to an action definition, delay giving it the default class from the package until that action is actually asked for.

sutter2k added a comment - 15/Jan/08 01:52 PM
Related material

thread on nabble discussion here
http://www.nabble.com/http%3A--struts.apache.org-dtds-struts-2.0.dtd-needs-to-be-updated-td14742352.html#a14845312


Delaying given an action the class if none supplied may be a route that is needed for being able to refer to {packageName} for wildcard settings. This is also and initiative that should be looked at/considered.
http://www.nabble.com/Wildcard-mappings-templates-need-to-refer-to-a-package-name-td14737911.html#a14801576

Rainer Hermanns added a comment - 02/Mar/08 07:43 AM
Patch applied, thanks Matthew