You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Daniel Woo <Da...@gmail.com> on 2009/01/09 05:23:18 UTC
default mapping with annotation
Hi guys,
I have a default mapping, eg,
Code:
<action name="*" >
<result>/_{1}.jsp</result>
</action>
<action name="HelloWorld" class="test.action.HelloWorld" >
<result name="success">/HelloWorld.jsp</result>
</action>
In this case, if an action can not be matched it will be forwarded to
/_{action name}.jsp, eg, /X.action will be forwarded to _X.jsp
It works great, however if I remove XML configurations of the action
HelloWorld, and use annotation with test.action.HelloWorld in code, then my
request to /HelloWorld.action goes to /_HelloWorld.jsp instead of class
test.action.HelloWorld.
So how can I use the default mapping with annotation, and fall to default
mapping only when no match in BOTH ANNOTATION AND XML configuration?
--
View this message in context: http://www.nabble.com/default-mapping-with-annotation-tp21366005p21366005.html
Sent from the Struts - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: default mapping with annotation
Posted by Daniel Woo <Da...@gmail.com>.
I think I probably always use explicit mapping in annotation or XML, and not
using the wild card fall-back mapping. It won't be too much burden for me to
explicitly do that and that's also less error-prone. Thanks a lot for your
suggestion!
Wes Wannemacher wrote:
>
> On Thu, 2009-01-08 at 21:09 -0800, Daniel Woo wrote:
>> I am using Conventions since annotation is moved into Conventions in
>> 2.1.2.
>> The problem is that I like explicit declaration of Action/URL/namespace
>> etc
>> in annotations rather than implicit declaration provided by Convertion,
>> only
>> for a few simple JSP files I want it to be mapped implicitly with a
>> wild-card in struts.xml. It seems that it's impossible to do that, I have
>> to
>> either use implicit with Conventions suggested, or use explicit
>> declaration
>> without "default mapping"
>
> It's not necessarily either implicit with Conventions or explicit with
> XML... I mix the two all the time. The problem is really just the
> wildcard. Go ahead and map all the actions you want, either in XML or
> annotations. What I was suggesting is that you simply adopt the
> convention for default mappings for the actions you are trying to catch
> with your wildcard.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
>
--
View this message in context: http://www.nabble.com/default-mapping-with-annotation-tp21366005p21366866.html
Sent from the Struts - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: default mapping with annotation
Posted by Wes Wannemacher <we...@wantii.com>.
On Thu, 2009-01-08 at 21:09 -0800, Daniel Woo wrote:
> I am using Conventions since annotation is moved into Conventions in 2.1.2.
> The problem is that I like explicit declaration of Action/URL/namespace etc
> in annotations rather than implicit declaration provided by Convertion, only
> for a few simple JSP files I want it to be mapped implicitly with a
> wild-card in struts.xml. It seems that it's impossible to do that, I have to
> either use implicit with Conventions suggested, or use explicit declaration
> without "default mapping"
It's not necessarily either implicit with Conventions or explicit with
XML... I mix the two all the time. The problem is really just the
wildcard. Go ahead and map all the actions you want, either in XML or
annotations. What I was suggesting is that you simply adopt the
convention for default mappings for the actions you are trying to catch
with your wildcard.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: default mapping with annotation
Posted by Daniel Woo <Da...@gmail.com>.
Wes Wannemacher wrote:
>
> I'm surprised this works, order is significant, so the wildcard would
> match and look for _HelloWorld.jsp... But, since you indicate that it
> does, I'm guessing in your struts.xml, you have the right order.
>
Yep, I have the right order in my struts.xml, this is a reformat :-)
Wes Wannemacher wrote:
>
> How are you doing the annotation configuration, meaning, which plugin?
> Are you using Codebehind, Conventions, Zero-Config, etc. Most of the
> plugins perform mappings by using a rewritten UnknownHandler, which
> means that XML configuration takes precedence. You may be in a bit of a
> pickle, since you want a default catch-all... I would suggest looking at
> the Conventions plugin since it will do what you are looking for,
> without the XML configuration. It will provide a default mapping by
> backing each action request with ActionSupport if a JSP file exists on
> the file system matching the URI of the incoming request.
>
I am using Conventions since annotation is moved into Conventions in 2.1.2.
The problem is that I like explicit declaration of Action/URL/namespace etc
in annotations rather than implicit declaration provided by Convertion, only
for a few simple JSP files I want it to be mapped implicitly with a
wild-card in struts.xml. It seems that it's impossible to do that, I have to
either use implicit with Conventions suggested, or use explicit declaration
without "default mapping"
--
View this message in context: http://www.nabble.com/default-mapping-with-annotation-tp21366005p21366353.html
Sent from the Struts - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: default mapping with annotation
Posted by Wes Wannemacher <we...@wantii.com>.
On Thu, 2009-01-08 at 20:23 -0800, Daniel Woo wrote:
> Hi guys,
>
> I have a default mapping, eg,
>
> Code:
> <action name="*" >
> <result>/_{1}.jsp</result>
> </action>
> <action name="HelloWorld" class="test.action.HelloWorld" >
> <result name="success">/HelloWorld.jsp</result>
> </action>
>
I'm surprised this works, order is significant, so the wildcard would
match and look for _HelloWorld.jsp... But, since you indicate that it
does, I'm guessing in your struts.xml, you have the right order.
>
>
> In this case, if an action can not be matched it will be forwarded to
> /_{action name}.jsp, eg, /X.action will be forwarded to _X.jsp
>
> It works great, however if I remove XML configurations of the action
> HelloWorld, and use annotation with test.action.HelloWorld in code, then my
> request to /HelloWorld.action goes to /_HelloWorld.jsp instead of class
> test.action.HelloWorld.
>
> So how can I use the default mapping with annotation, and fall to default
> mapping only when no match in BOTH ANNOTATION AND XML configuration?
How are you doing the annotation configuration, meaning, which plugin?
Are you using Codebehind, Conventions, Zero-Config, etc. Most of the
plugins perform mappings by using a rewritten UnknownHandler, which
means that XML configuration takes precedence. You may be in a bit of a
pickle, since you want a default catch-all... I would suggest looking at
the Conventions plugin since it will do what you are looking for,
without the XML configuration. It will provide a default mapping by
backing each action request with ActionSupport if a JSP file exists on
the file system matching the URI of the incoming request.
-Wes
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org