Use Pattern Matching Wildcards in  Configurations

Action configuration files are somehow able to grow to
extremely large at incredible speeds. On way to combat this
phenomenon is to use pattern matching. Pattern matching works
by defining one or more patterns that URLs will conform to.
An example will be an easy way to see how things work. Let’s
say that the URLs in your web application always follows the
pattern “/{module}/{entity}/{action}.action”. This is a common
pattern;       examples         would        be       the    URL’s
“/admin/User/edit.action”,         “/admin/User/list.action”     and
“/admin/User/add.action”.

The class configuration is such that there is a Struts2 action class
with the name “{entity}Action”, and each {action} is method on
the action class. All the results from invoking the action’s
methods will result in either the update page for the entity being
displayed, or a list of all the entities being displayed.

For our example, the “struts.xml” configuration will look like
this:

*<action name=”*/*/*” method=”{3}”
           class=”com.infoq.actions.{1}.{2}Action”>
      <result name=”view”>/{1}/update{2}.jsp</result>
      <result name=”list”>/{1}/list.jsp</result>
</action>*

Each asterisk in the actions name is a wildcard. In the example,
only asterisks are used – but this need not be the case. For
example, say you wish to map all entity view actions together.
Something like ‘name=”/*/View*”’ would do the trick. Token
identifiers, {1}, {2}, etc., are then used to obtain the text values
harvested from the wildcards (where the numeric value
correlating to the position of the asterisk, ascending from left to
right).

In the “struts.properties” configuration file (or using the constant
tag in the “struts.xml” configuration file) you need to ensure the
following property is correctly set:

struts.enable.SlashesInActionNames = true

This property allows slashes in the name of the action. Struts2’s
default configuration is to not have slashes in the action name,
instead using packages for namespace separation.

Finally, there is no shortcut if you are providing validation and
conversion property files rather than using annotations. We’ll
talk about this more in following sections. Each needs to
contain the full name of the action, along with the necessary
extension: i.e. “edit-validation.xml” and “edit-conversion.xml”
for the original example, in the “com.infoq.actions.admin”
package.


2009/7/9 <mailtolouis2020-str...@yahoo.com>

> Thanks for let me know another struts2 book, have a quick look in it,
> didn't found any good tip to solve my problem.
>
> Regards
> Louis
>
>
>
> ________________________________
> From: Oscar Alvarez <oialva...@gmail.com>
> To: Struts Users Mailing List <user@struts.apache.org>
> Sent: Wednesday, July 8, 2009 7:09:35 PM
> Subject: Re: dynamic return when validation failed
>
> 2009/7/8 Oscar Alvarez <oialva...@gmail.com>
>
> > Hi...
> >
> > Try to get the Ian Roughley's "Starting Struts2 online" ebook for free,
> and
> > study "PRODUCTIVITY TIPS" -> "Re-Using Action Configurations"... and see
> if
> > there are some other tips for you.
> >
>
>
> And of course "PRODUCTIVITY TIPS" -> "Use Pattern Matching Wildcards in
> Configurations" too.
>
>
>
> >
> > HTH
> >
> > 2009/7/8 Greg Lindholm <greg.lindh...@gmail.com>
> >
> > > Greg Lindholm wrote:
> >> >
> >> >> The referer header will contain the URL of the last request, which
> will
> >> be
> >> >> the action URL not the jsp page that rendered the result. So this
> >> wouldn't
> >> >> help the OP if I understood his problem.
> >> >>
> >> >
> >> > I think you misunderstand what the referer field contains.  It'll be
> the
> >> > url that was displaying in the address field on the page from which
> the
> >> form
> >> > was submitted.  http://en.wikipedia.org/wiki/HTTP_referrer Note that
> it
> >> > can be forged, etc.
> >> >
> >> >
> >> Not sure why you think I don't understand referer. In a struts app what
> >> you
> >> see in the address field is the "action URL" (e.g.
> >> http://host/MyAction.action) you don't ever see the JSP page name that
> >> rendered the page. The OP seemed to be looking for the name of the jsp
> >> page
> >> so don't see how this would help.
> >>
> >
> >
> >
> > --
> > Atentamente
> > Óscar Álvarez Vielma
> > (09) 8416 4052
> >
>
>
>
> --
> Atentamente
> Óscar Álvarez Vielma
> (09) 8416 4052
>



-- 
Atentamente
Óscar Álvarez Vielma
(09) 8416 4052

Reply via email to