You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@struts.apache.org by "Leonard Broman (JIRA)" <ji...@apache.org> on 2008/10/19 20:01:37 UTC

[jira] Created: (WW-2842) Wildcards in namespace maps url values to controller parameters

Wildcards in namespace maps url values to controller parameters
---------------------------------------------------------------

                 Key: WW-2842
                 URL: https://issues.apache.org/struts/browse/WW-2842
             Project: Struts 2
          Issue Type: Improvement
          Components: Plugin - REST
            Reporter: Leonard Broman
            Priority: Minor


Implement wildcard functionality in namespace declaration to be able to map URL values to controller properties, or more appropriately, push them to the value stack.

This has been discussed lightly on the user mailing list and there is a short notice on the jroller blog by Don Brown http://www.jroller.com/mrdon/entry/struts_2_rest_todos .

Simple example:

We may want to map a nice and clean url: GET /report/lbroman/2008/january
To a ReportController where the values lbroman, 2008, january will be set on properties on the Controller.
Using the @Namespace annotation, a namespace declaration like "/report/{user}/{year}/{month}" will use the wildcard mapping to map "lbroman", "2008", "january" to setUser(), setYear() and setMonth() respectively.

Note that this overrides the default setId() for the first parameter.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (WW-2842) Wildcards in namespace maps url values to controller parameters

Posted by "James Holmes (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/struts/browse/WW-2842?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

James Holmes updated WW-2842:
-----------------------------

    Fix Version/s: Future

> Wildcards in namespace maps url values to controller parameters
> ---------------------------------------------------------------
>
>                 Key: WW-2842
>                 URL: https://issues.apache.org/struts/browse/WW-2842
>             Project: Struts 2
>          Issue Type: Improvement
>          Components: Plugin - REST
>            Reporter: Leonard Broman
>            Priority: Minor
>             Fix For: Future
>
>
> Implement wildcard functionality in namespace declaration to be able to map URL values to controller properties, or more appropriately, push them to the value stack.
> This has been discussed lightly on the user mailing list and there is a short notice on the jroller blog by Don Brown http://www.jroller.com/mrdon/entry/struts_2_rest_todos .
> Simple example:
> We may want to map a nice and clean url: GET /report/lbroman/2008/january
> To a ReportController where the values lbroman, 2008, january will be set on properties on the Controller.
> Using the @Namespace annotation, a namespace declaration like "/report/{user}/{year}/{month}" will use the wildcard mapping to map "lbroman", "2008", "january" to setUser(), setYear() and setMonth() respectively.
> Note that this overrides the default setId() for the first parameter.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Issue Comment Edited: (WW-2842) Wildcards in namespace maps url values to controller parameters

Posted by "Ryan Wong (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/struts/browse/WW-2842?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=45395#action_45395 ] 

lazing edited comment on WW-2842 at 1/6/09 7:45 PM:
-------------------------------------------------------

It block me for further dev... 
currently I am trying to fix it myself..

I will post here if any improvement.

more: This request is just to make conversation plugin work together with REST 

      was (Author: lazing):
    It block me for further dev... 
currently I am trying to fix it myself..

I will post here if any improvement.
  
> Wildcards in namespace maps url values to controller parameters
> ---------------------------------------------------------------
>
>                 Key: WW-2842
>                 URL: https://issues.apache.org/struts/browse/WW-2842
>             Project: Struts 2
>          Issue Type: Improvement
>          Components: Plugin - REST
>            Reporter: Leonard Broman
>            Priority: Minor
>             Fix For: Future
>
>
> Implement wildcard functionality in namespace declaration to be able to map URL values to controller properties, or more appropriately, push them to the value stack.
> This has been discussed lightly on the user mailing list and there is a short notice on the jroller blog by Don Brown http://www.jroller.com/mrdon/entry/struts_2_rest_todos .
> Simple example:
> We may want to map a nice and clean url: GET /report/lbroman/2008/january
> To a ReportController where the values lbroman, 2008, january will be set on properties on the Controller.
> Using the @Namespace annotation, a namespace declaration like "/report/{user}/{year}/{month}" will use the wildcard mapping to map "lbroman", "2008", "january" to setUser(), setYear() and setMonth() respectively.
> Note that this overrides the default setId() for the first parameter.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (WW-2842) Wildcards in namespace maps url values to controller parameters

Posted by "Ryan Wong (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/struts/browse/WW-2842?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Ryan Wong updated WW-2842:
--------------------------

    Attachment: rest plugin convention fix.zip

hello, I have fix the problem initially for my project.
here the code and test, wish could be useful.

> Wildcards in namespace maps url values to controller parameters
> ---------------------------------------------------------------
>
>                 Key: WW-2842
>                 URL: https://issues.apache.org/struts/browse/WW-2842
>             Project: Struts 2
>          Issue Type: Improvement
>          Components: Plugin - REST
>            Reporter: Leonard Broman
>            Priority: Minor
>             Fix For: Future
>
>         Attachments: rest plugin convention fix.zip
>
>
> Implement wildcard functionality in namespace declaration to be able to map URL values to controller properties, or more appropriately, push them to the value stack.
> This has been discussed lightly on the user mailing list and there is a short notice on the jroller blog by Don Brown http://www.jroller.com/mrdon/entry/struts_2_rest_todos .
> Simple example:
> We may want to map a nice and clean url: GET /report/lbroman/2008/january
> To a ReportController where the values lbroman, 2008, january will be set on properties on the Controller.
> Using the @Namespace annotation, a namespace declaration like "/report/{user}/{year}/{month}" will use the wildcard mapping to map "lbroman", "2008", "january" to setUser(), setYear() and setMonth() respectively.
> Note that this overrides the default setId() for the first parameter.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Issue Comment Edited: (WW-2842) Wildcards in namespace maps url values to controller parameters

Posted by "Ryan Wong (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/struts/browse/WW-2842?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=45395#action_45395 ] 

lazing edited comment on WW-2842 at 1/8/09 7:00 PM:
-------------------------------------------------------

It block me for further dev... 
currently I am trying to fix it myself..

I will post here if any improvement.

more: This request is just to make convention plugin work together with REST 

      was (Author: lazing):
    It block me for further dev... 
currently I am trying to fix it myself..

I will post here if any improvement.

more: This request is just to make conversation plugin work together with REST 
  
> Wildcards in namespace maps url values to controller parameters
> ---------------------------------------------------------------
>
>                 Key: WW-2842
>                 URL: https://issues.apache.org/struts/browse/WW-2842
>             Project: Struts 2
>          Issue Type: Improvement
>          Components: Plugin - REST
>            Reporter: Leonard Broman
>            Priority: Minor
>             Fix For: Future
>
>
> Implement wildcard functionality in namespace declaration to be able to map URL values to controller properties, or more appropriately, push them to the value stack.
> This has been discussed lightly on the user mailing list and there is a short notice on the jroller blog by Don Brown http://www.jroller.com/mrdon/entry/struts_2_rest_todos .
> Simple example:
> We may want to map a nice and clean url: GET /report/lbroman/2008/january
> To a ReportController where the values lbroman, 2008, january will be set on properties on the Controller.
> Using the @Namespace annotation, a namespace declaration like "/report/{user}/{year}/{month}" will use the wildcard mapping to map "lbroman", "2008", "january" to setUser(), setYear() and setMonth() respectively.
> Note that this overrides the default setId() for the first parameter.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (WW-2842) Wildcards in namespace maps url values to controller parameters

Posted by "Ryan Wong (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/struts/browse/WW-2842?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=45395#action_45395 ] 

Ryan Wong commented on WW-2842:
-------------------------------

It block me for further dev... 
currently I am trying to fix it myself..

I will post here if any improvement.

> Wildcards in namespace maps url values to controller parameters
> ---------------------------------------------------------------
>
>                 Key: WW-2842
>                 URL: https://issues.apache.org/struts/browse/WW-2842
>             Project: Struts 2
>          Issue Type: Improvement
>          Components: Plugin - REST
>            Reporter: Leonard Broman
>            Priority: Minor
>             Fix For: Future
>
>
> Implement wildcard functionality in namespace declaration to be able to map URL values to controller properties, or more appropriately, push them to the value stack.
> This has been discussed lightly on the user mailing list and there is a short notice on the jroller blog by Don Brown http://www.jroller.com/mrdon/entry/struts_2_rest_todos .
> Simple example:
> We may want to map a nice and clean url: GET /report/lbroman/2008/january
> To a ReportController where the values lbroman, 2008, january will be set on properties on the Controller.
> Using the @Namespace annotation, a namespace declaration like "/report/{user}/{year}/{month}" will use the wildcard mapping to map "lbroman", "2008", "january" to setUser(), setYear() and setMonth() respectively.
> Note that this overrides the default setId() for the first parameter.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (WW-2842) Wildcards in namespace maps url values to controller parameters

Posted by "Jeromy Evans (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/struts/browse/WW-2842?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=45461#action_45461 ] 

Jeromy Evans commented on WW-2842:
----------------------------------

Don implemented the NamedVariablePatternMatcher in about mid 2008 but it's never been fully documented.  Your approach using a custom ActionMapper is also appropriate.

The NamedVariablePatternMatcher will be properly documented in the 2.1.6 release.

I created an example for another user at: http://www.blueskyminds.com.au/url-hierarchy/

Here's the relevant description that's being incorporated in to the docs regarding wildcards:

The PatternMatcher is used to process variables in the path of a request.  It allows an action's namespace to contain patterns that match wildcards and/or to extract parameters from the request's path.

The default implementation supports the * and ? notation within the namespaces (see xxx).  Switching the implementation to the NamedVariablePatternMatcher allows named parameters to be included within the namespace.

eg. for a request to "/users/23/details.action", if the action's namespace is "/users/{userID}/", the PatternMatcher will attempt to set the action's userID property to 23 as if this were a request parameter.

The NamedVariablePatternMatcher is setup by:
1. Declaring the new PatternMatcher bean (undefined by default); and
2. setting the struts.patternMatcher property to the new instance's name

<code>
<bean type="com.opensymphony.xwork2.util.PatternMatcher" name="namedVariablePatternMatcher" class="com.opensymphony.xwork2.util.NamedVariablePatternMatcher"/>
<constant name="struts.patternMatcher" value="namedVariablePatternMatcher"/>
</code>

Namespaces can be configured in struts.xml or using annotations as usual:

<code>
@Namespace{"/users/{userID}");
public class DetailsAction exends ActionSupport {
  private Long userID;
  public void setUserID(Long userID) {...}
}
</code>

Caution: Only one PatternMatcher implementation can be used at a time.  The two implementations included with Struts 2 are mutually exclusive.  You cannot use Wildcards and Named Variable patterns at the same application (if that were required, you'd need to create a custom PatternMatcher implementation).

Caution:  Some tags tags not are 100% compatible with variables in the namespace. F or instance, they may write the literal namespace into the HTML (eg /{user}/2w) instead of the path used in the request (ie. /brett/24).  This usually affects attributes that attempt to guess the namespace of an action (eg. Form tag, Action tag, action=). This problem can be avoided by using HTML tags directly with relative paths or explicit URLs.

Tip: similar functionality can also be implemented using a custom ActionMapper.  The ActionMapper will need to parse the namespace and request itself to set parameters on the matched action.  The default ActonMapper is responsible for invoking the PatternMatcher. 

> Wildcards in namespace maps url values to controller parameters
> ---------------------------------------------------------------
>
>                 Key: WW-2842
>                 URL: https://issues.apache.org/struts/browse/WW-2842
>             Project: Struts 2
>          Issue Type: Improvement
>          Components: Plugin - REST
>            Reporter: Leonard Broman
>            Priority: Minor
>             Fix For: Future
>
>         Attachments: rest plugin convention fix.zip
>
>
> Implement wildcard functionality in namespace declaration to be able to map URL values to controller properties, or more appropriately, push them to the value stack.
> This has been discussed lightly on the user mailing list and there is a short notice on the jroller blog by Don Brown http://www.jroller.com/mrdon/entry/struts_2_rest_todos .
> Simple example:
> We may want to map a nice and clean url: GET /report/lbroman/2008/january
> To a ReportController where the values lbroman, 2008, january will be set on properties on the Controller.
> Using the @Namespace annotation, a namespace declaration like "/report/{user}/{year}/{month}" will use the wildcard mapping to map "lbroman", "2008", "january" to setUser(), setYear() and setMonth() respectively.
> Note that this overrides the default setId() for the first parameter.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (WW-2842) Wildcards in namespace maps url values to controller parameters

Posted by "Matt York (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/struts/browse/WW-2842?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=46992#action_46992 ] 

Matt York commented on WW-2842:
-------------------------------

Jeromy,

It seems your example is offline, is there any chance you could put it back up? I'm attempting to get hierarchial urls working with the Struts2 REST Controllers and so far have not met with success.
 

> Wildcards in namespace maps url values to controller parameters
> ---------------------------------------------------------------
>
>                 Key: WW-2842
>                 URL: https://issues.apache.org/struts/browse/WW-2842
>             Project: Struts 2
>          Issue Type: Improvement
>          Components: Plugin - REST
>            Reporter: Leonard Broman
>            Priority: Minor
>             Fix For: Future
>
>         Attachments: rest plugin convention fix.zip
>
>
> Implement wildcard functionality in namespace declaration to be able to map URL values to controller properties, or more appropriately, push them to the value stack.
> This has been discussed lightly on the user mailing list and there is a short notice on the jroller blog by Don Brown http://www.jroller.com/mrdon/entry/struts_2_rest_todos .
> Simple example:
> We may want to map a nice and clean url: GET /report/lbroman/2008/january
> To a ReportController where the values lbroman, 2008, january will be set on properties on the Controller.
> Using the @Namespace annotation, a namespace declaration like "/report/{user}/{year}/{month}" will use the wildcard mapping to map "lbroman", "2008", "january" to setUser(), setYear() and setMonth() respectively.
> Note that this overrides the default setId() for the first parameter.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.