You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Binil Thomas <bi...@gmail.com> on 2008/10/10 04:23:36 UTC

How to use pattern matching wild-card in action names?

Hi all,

I am trying to make my URLs more readable, and was hoping that I could use
pattern-matching wildcards in action declarations. I have not been able to
get it working so far.

In my struts.xml, I have:
<struts> 
    <constant name="struts.enable.SlashesInActionNames" value="true"/>
    <constant name="struts.action.extension" value="" /> 
    <package name="s2" extends="struts-default" namespace="/">
        <action name="widgets*" class="app.WidgetsAction" method="index">
            <result name="success">index.jsp</result>
        </action>
    </package>
</struts>

Now, /widgets get routed to be my action. /widgets1 also get routed to the
action as one would expect. But /widgets/1 does not get routed to my action.
Why is this so? I tried the pattern "widgets/*" also, but that does not work
either. I think I have not been able to coax Struts to have slashes in the
name of action. Any help is appreciated.

Thanks,
Binil
-- 
View this message in context: http://www.nabble.com/How-to-use-pattern-matching-wild-card-in-action-names--tp19910768p19910768.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: How to use pattern matching wild-card in action names?

Posted by Binil Thomas <bi...@gmail.com>.
Thanks Lukasz, using:

<package name="default" extends="struts-default" namespace="">
 ..
</package>

worked!



Lukasz Lenart wrote:
> 
> Hi,
> 
> If Struts2 couldn't find action in given namespace ("/") it will try
> to find it in default namespace ("/" is not default namespace), remove
> namespace declaration and try once again.
> 
> 
> Regards
> -- 
> Lukasz
> http://www.lenart.org.pl/
> 
> ---------------------------------------------------------------------
> 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/How-to-use-pattern-matching-wild-card-in-action-names--tp19910768p19929084.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: How to use pattern matching wild-card in action names?

Posted by Lukasz Lenart <lu...@googlemail.com>.
Hi,

If Struts2 couldn't find action in given namespace ("/") it will try
to find it in default namespace ("/" is not default namespace), remove
namespace declaration and try once again.


Regards
-- 
Lukasz
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: How to use pattern matching wild-card in action names?

Posted by Binil Thomas <bi...@gmail.com>.
To answer my own question - wildcards do not seem to work if the namespace is
"/". I tried adding a namespace and it works. Can someone explain why this
is so?

<struts> 
    <constant name="struts.enable.SlashesInActionNames" value="true"/>
    <constant name="struts.action.extension" value=""/>
    
    <package name="default" extends="struts-default" namespace="/w">
        <action name="widgets/*" class="app.WidgetsAction">
            {1}
            <result name="success">/index.jsp</result>
        </action>
    </package>
</struts>

Thanks,
Binil


Binil Thomas wrote:
> 
> Hi all,
> 
> I am trying to make my URLs more readable, and was hoping that I could use
> pattern-matching wildcards in action declarations. I have not been able to
> get it working so far.
> 
> In my struts.xml, I have:
> <struts> 
>     <constant name="struts.enable.SlashesInActionNames" value="true"/>
>     <constant name="struts.action.extension" value="" /> 
>     <package name="s2" extends="struts-default" namespace="/">
>         <action name="widgets*" class="app.WidgetsAction" method="index">
>             <result name="success">index.jsp</result>
>         </action>
>     </package>
> </struts>
> 
> Now, /widgets get routed to be my action. /widgets1 also get routed to the
> action as one would expect. But /widgets/1 does not get routed to my
> action. Why is this so? I tried the pattern "widgets/*" also, but that
> does not work either. I think I have not been able to coax Struts to have
> slashes in the name of action. Any help is appreciated.
> 
> Thanks,
> Binil
> 

-- 
View this message in context: http://www.nabble.com/How-to-use-pattern-matching-wild-card-in-action-names--tp19910768p19912812.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: How to use pattern matching wild-card in action names?

Posted by Dave Newton <ne...@yahoo.com>.
--- On Thu, 10/9/08, Binil Thomas wrote:
> I think I have not been able to coax Struts to have
> slashes in the name of action.

Have you set the "struts.enable.SlashesInActionNames" property to "true"?

Dave


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