struts2annotationstiles2

Struts2, How to define @Result type parameter as tiles result


i am having trouble defining 'type' parameter of @Result annotation

here is my action annotation:

@Action(value="login", 
    results=@Result(name="success",location="index.page", type="tiles" ))

where index.page is my tiles definition, how do i define that 'tiles' is actually tiles result ?

before i was using struts.xml for config, and i could just place there

<result-types>
    <result-type name="tiles" class="org.apache.struts2.views.tiles.TilesResult" />
</result-types>

whatever i try i always get:

SEVERE: Dispatcher initialization failed
Unable to load configuration. - [unknown location]
...
Caused by: The Result type [tiles] which is defined in the Result annotation ... 
could not be found as a result-type defined for the Struts/XWork package 
[com.action#convention-default#] - [unknown location]

Solution

  • Here is the configuration I use in my annotations based rest setup. Your result types need to be wrapped in whatever default package you're using for your actions:

    <constant name="struts.convention.default.parent.package" value="restful"/>
    
    <package name="restful"  extends="rest-default, struts-default, json-default">
        <result-types>
            <result-type name="tiles" class="org.apache.struts2.views.tiles.TilesResult" />
            <result-type name="json" class="com.googlecode.jsonplugin.JSONResult"/>
        </result-types> 
    
    </package>