You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Ken McWilliams <ke...@gmail.com> on 2012/11/24 22:40:54 UTC

struts2 conventions plugin - how to override result type

Using struts2-convention-plugin-2.3.1.2 currently.

I want conventions to still automatically find my actions, that is
determine  struts2 packages from java package structure and Identify action
names from Java Action classes, but I want it to stop there I want it to
universally use my custom result type for all actions.

So far I have tried the following:

1) Explicitly setting the conventions parent package
<constant name="struts.convention.default.parent.package"
value="tiles-package"/>

2) Configuring that package with my result as the default

    <package  name="tiles-package" extends="convention-default">
        <result-types>
            <result-type default="true" name="tiles"
class="com.kenmcwilliams.tiles.result.TilesResult"/>
        </result-types>
    </package>

So far I can only get my result to take effect if I override conventions
with annotations.

So far the following works:

package com.kenmcwilliams.employmentsystem.action.test;

import com.opensymphony.xwork2.ActionSupport;
import org.apache.struts2.convention.annotation.Result;

@Result(type="tiles")
public class TilesAction extends ActionSupport{

}

The tiles result checks the location parameter which if not specified in
the result annotation it will look up the namespace and action name, then
using tiles regexp convention can be carried on through tiles.

My current issue is dropping the need for '
@Result(type="tiles")' on every class. Any advice?

Further I've created my own ConventionsServiceImpl if that helps, all it
currently does is print incoming parameters and return values to logs. I
haven't really been able to figure out what I can use it for.

Re: struts2 conventions plugin - how to override result type

Posted by Lukasz Lenart <lu...@apache.org>.
2012/12/6 Ken McWilliams <ke...@gmail.com>:
> The right thing to do was override the ConventionsUnknownHandler like you
> suggested. Right now the code is pretty ugly, I need to add unit tests to
> my TilesUnknownHandler and then I wouldn't mind contributing it.
>
> When the struts2-tiles-plugin is upgraded to account for tiles3 it would be
> nice if it would check to see if the conventions plugin is in the class
> path and then use then use the tiles result type by default (or if not by
> default then as at least as an option).
>
> Currently either the TilesUnknownHandler or the TilesResultType produces a
> location of (namespace + "#" + file) and feeds that string as a tiles
> definition:
>
>     <definition name="REGEXP:(.*)#(.*)"  extends="/test">
>         <put-attribute name="body" value="/WEB-INF/content{1}/{2}"/>
>     </definition>
>
> The thing now is to define a convention for locating templates that makes
> sense. Someway of dynamically generating tiles definitions from the content
> under /WEB-INF.

If you will be ready, feel free to register an issue with patch attached :-)


Kind regards
-- 
Łukasz
+ 48 606 323 122 http://www.lenart.org.pl/

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: struts2 conventions plugin - how to override result type

Posted by Ken McWilliams <ke...@gmail.com>.
The right thing to do was override the ConventionsUnknownHandler like you
suggested. Right now the code is pretty ugly, I need to add unit tests to
my TilesUnknownHandler and then I wouldn't mind contributing it.

When the struts2-tiles-plugin is upgraded to account for tiles3 it would be
nice if it would check to see if the conventions plugin is in the class
path and then use then use the tiles result type by default (or if not by
default then as at least as an option).

Currently either the TilesUnknownHandler or the TilesResultType produces a
location of (namespace + "#" + file) and feeds that string as a tiles
definition:

    <definition name="REGEXP:(.*)#(.*)"  extends="/test">
        <put-attribute name="body" value="/WEB-INF/content{1}/{2}"/>
    </definition>

The thing now is to define a convention for locating templates that makes
sense. Someway of dynamically generating tiles definitions from the content
under /WEB-INF.


On Wed, Nov 28, 2012 at 4:33 PM, Ken McWilliams <ke...@gmail.com>wrote:

> Sorry I wrote that before really looking the UnknownHandler, it is the
> right path.
>
> I'll get back with the results, and later I hope to have some questions
> about run time configuration (something I want to try is swapping the order
> of interceptors in a named stack at runtime).
>
>
> On Wed, Nov 28, 2012 at 1:08 PM, Lukasz Lenart <lu...@apache.org>wrote:
>
>> 2012/11/26 Ken McWilliams <ke...@gmail.com>:
>> > I've yet to try this but how do I tie this into conventions.
>>
>> Just add
>> <bean type="....UnknownHandler" class="....MyUnknownHandler"
>> name="myUnknownHandler"/>
>>
>> > My issue is that I am following conventions, there are JSPs located as
>> > views for the action (that is, located where conventions would expect to
>> > find view). My idea is to create a tiles plugin that keeps struts
>> > conventions as near as possible to the way they are. That is the body
>> > content is always assumed to be at
>> > /WEB-INF/content/{package}/{conventions-action-name}.{viewType}
>> >
>> > So conventions will still have a valid result, so the UnknownHandler
>> isn't
>> > ideal because conventions will think there is a valid result, unless
>> there
>> > is some way to update the configuration even if it is to intentionally
>> > break it...
>> >
>> > Is it possible to do something like that with a custom ActionProxy?
>>
>> I don't know, just try and share your code :-)
>>
>>
>> Regards
>> --
>> Łukasz
>> + 48 606 323 122 http://www.lenart.org.pl/
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>

Re: struts2 conventions plugin - how to override result type

Posted by Ken McWilliams <ke...@gmail.com>.
Sorry I wrote that before really looking the UnknownHandler, it is the
right path.

I'll get back with the results, and later I hope to have some questions
about run time configuration (something I want to try is swapping the order
of interceptors in a named stack at runtime).


On Wed, Nov 28, 2012 at 1:08 PM, Lukasz Lenart <lu...@apache.org>wrote:

> 2012/11/26 Ken McWilliams <ke...@gmail.com>:
> > I've yet to try this but how do I tie this into conventions.
>
> Just add
> <bean type="....UnknownHandler" class="....MyUnknownHandler"
> name="myUnknownHandler"/>
>
> > My issue is that I am following conventions, there are JSPs located as
> > views for the action (that is, located where conventions would expect to
> > find view). My idea is to create a tiles plugin that keeps struts
> > conventions as near as possible to the way they are. That is the body
> > content is always assumed to be at
> > /WEB-INF/content/{package}/{conventions-action-name}.{viewType}
> >
> > So conventions will still have a valid result, so the UnknownHandler
> isn't
> > ideal because conventions will think there is a valid result, unless
> there
> > is some way to update the configuration even if it is to intentionally
> > break it...
> >
> > Is it possible to do something like that with a custom ActionProxy?
>
> I don't know, just try and share your code :-)
>
>
> Regards
> --
> Łukasz
> + 48 606 323 122 http://www.lenart.org.pl/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: struts2 conventions plugin - how to override result type

Posted by Lukasz Lenart <lu...@apache.org>.
2012/11/26 Ken McWilliams <ke...@gmail.com>:
> I've yet to try this but how do I tie this into conventions.

Just add
<bean type="....UnknownHandler" class="....MyUnknownHandler"
name="myUnknownHandler"/>

> My issue is that I am following conventions, there are JSPs located as
> views for the action (that is, located where conventions would expect to
> find view). My idea is to create a tiles plugin that keeps struts
> conventions as near as possible to the way they are. That is the body
> content is always assumed to be at
> /WEB-INF/content/{package}/{conventions-action-name}.{viewType}
>
> So conventions will still have a valid result, so the UnknownHandler isn't
> ideal because conventions will think there is a valid result, unless there
> is some way to update the configuration even if it is to intentionally
> break it...
>
> Is it possible to do something like that with a custom ActionProxy?

I don't know, just try and share your code :-)


Regards
-- 
Łukasz
+ 48 606 323 122 http://www.lenart.org.pl/

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: struts2 conventions plugin - how to override result type

Posted by Ken McWilliams <ke...@gmail.com>.
I've yet to try this but how do I tie this into conventions.

My issue is that I am following conventions, there are JSPs located as
views for the action (that is, located where conventions would expect to
find view). My idea is to create a tiles plugin that keeps struts
conventions as near as possible to the way they are. That is the body
content is always assumed to be at
/WEB-INF/content/{package}/{conventions-action-name}.{viewType}

So conventions will still have a valid result, so the UnknownHandler isn't
ideal because conventions will think there is a valid result, unless there
is some way to update the configuration even if it is to intentionally
break it...

Is it possible to do something like that with a custom ActionProxy?

Maybe there is a way to create a preresult listener for all conventions,
that somehow does the job of a result handler and then aborts the real
result handler?


On Mon, Nov 26, 2012 at 1:20 PM, Lukasz Lenart <lu...@apache.org>wrote:

> Hi,
>
> There is no easy way right now, you can try to implement
> UnknownHandler or at least extend ConventionUnknownHandler and
> override handleUnknownResult() method
>
>
> Regards
> --
> Łukasz
> + 48 606 323 122 http://www.lenart.org.pl/
>
>
> 2012/11/24 Ken McWilliams <ke...@gmail.com>:
> > Using struts2-convention-plugin-2.3.1.2 currently.
> >
> > I want conventions to still automatically find my actions, that is
> > determine  struts2 packages from java package structure and Identify
> action
> > names from Java Action classes, but I want it to stop there I want it to
> > universally use my custom result type for all actions.
> >
> > So far I have tried the following:
> >
> > 1) Explicitly setting the conventions parent package
> > <constant name="struts.convention.default.parent.package"
> > value="tiles-package"/>
> >
> > 2) Configuring that package with my result as the default
> >
> >     <package  name="tiles-package" extends="convention-default">
> >         <result-types>
> >             <result-type default="true" name="tiles"
> > class="com.kenmcwilliams.tiles.result.TilesResult"/>
> >         </result-types>
> >     </package>
> >
> > So far I can only get my result to take effect if I override conventions
> > with annotations.
> >
> > So far the following works:
> >
> > package com.kenmcwilliams.employmentsystem.action.test;
> >
> > import com.opensymphony.xwork2.ActionSupport;
> > import org.apache.struts2.convention.annotation.Result;
> >
> > @Result(type="tiles")
> > public class TilesAction extends ActionSupport{
> >
> > }
> >
> > The tiles result checks the location parameter which if not specified in
> > the result annotation it will look up the namespace and action name, then
> > using tiles regexp convention can be carried on through tiles.
> >
> > My current issue is dropping the need for '
> > @Result(type="tiles")' on every class. Any advice?
> >
> > Further I've created my own ConventionsServiceImpl if that helps, all it
> > currently does is print incoming parameters and return values to logs. I
> > haven't really been able to figure out what I can use it for.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: struts2 conventions plugin - how to override result type

Posted by Lukasz Lenart <lu...@apache.org>.
Hi,

There is no easy way right now, you can try to implement
UnknownHandler or at least extend ConventionUnknownHandler and
override handleUnknownResult() method


Regards
-- 
Łukasz
+ 48 606 323 122 http://www.lenart.org.pl/


2012/11/24 Ken McWilliams <ke...@gmail.com>:
> Using struts2-convention-plugin-2.3.1.2 currently.
>
> I want conventions to still automatically find my actions, that is
> determine  struts2 packages from java package structure and Identify action
> names from Java Action classes, but I want it to stop there I want it to
> universally use my custom result type for all actions.
>
> So far I have tried the following:
>
> 1) Explicitly setting the conventions parent package
> <constant name="struts.convention.default.parent.package"
> value="tiles-package"/>
>
> 2) Configuring that package with my result as the default
>
>     <package  name="tiles-package" extends="convention-default">
>         <result-types>
>             <result-type default="true" name="tiles"
> class="com.kenmcwilliams.tiles.result.TilesResult"/>
>         </result-types>
>     </package>
>
> So far I can only get my result to take effect if I override conventions
> with annotations.
>
> So far the following works:
>
> package com.kenmcwilliams.employmentsystem.action.test;
>
> import com.opensymphony.xwork2.ActionSupport;
> import org.apache.struts2.convention.annotation.Result;
>
> @Result(type="tiles")
> public class TilesAction extends ActionSupport{
>
> }
>
> The tiles result checks the location parameter which if not specified in
> the result annotation it will look up the namespace and action name, then
> using tiles regexp convention can be carried on through tiles.
>
> My current issue is dropping the need for '
> @Result(type="tiles")' on every class. Any advice?
>
> Further I've created my own ConventionsServiceImpl if that helps, all it
> currently does is print incoming parameters and return values to logs. I
> haven't really been able to figure out what I can use it for.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org