Commits

Anonymous committed f1c7379

- WW-1477
- RestfulActionMapper getMapping and getUriFromMapping methods conflicts

git-svn-id: http://svn.opensymphony.com/svn/webwork/trunk@2953573baa09-0c28-0410-bef9-dab3c582ae83

  • Participants
  • Parent commits 03bf8b2

Comments (0)

Files changed (2)

File src/java/com/opensymphony/webwork/dispatcher/mapper/RestfulActionMapper.java

         // is being used.
         if ((mapping.getNamespace() == null) || (mapping.getNamespace().trim().length() <= 0)) {
             String base = mapping.getName();
-            for (Iterator iterator = mapping.getParams().entrySet().iterator(); iterator.hasNext();) {
+
+            // let's see if we have the <actionName>Id first, if so this should go first,
+            // cause in {#link #getMapping(HttpServletRequest) the <actionName>Id is expected to be
+            // first if the / separated element is odd
+            Map parameters = mapping.getParams();
+            if (parameters.containsKey(mapping.getName()+"Id")) {
+                base = base + "/" + parameters.get(mapping.getName()+"Id");
+            }
+
+            for (Iterator iterator = parameters.entrySet().iterator(); iterator.hasNext();) {
                 Map.Entry entry = (Map.Entry) iterator.next();
                 String name = (String) entry.getKey();
-                if (name.equals(mapping.getName() + "Id")) {
-                    base = base + "/" + entry.getValue();
-                    break;
+                if (! name.equals(mapping.getName() + "Id")) {
+                    base = base + "/" + entry.getKey() + "/" + entry.getValue();
                 }
             }
             return base;

File src/test/com/opensymphony/webwork/dispatcher/mapper/RestfulActionMapperTest.java

         am.setName("view");
         am.setParams(param);
 
-        assertEquals("view", mapper.getUriFromActionMapping(am));
+        assertEquals("view/article/123", mapper.getUriFromActionMapping(am));
     }
 
     public void testGetUriParamId() {
         am.setName("view");
         am.setParams(param);
 
-        assertEquals("view/456", mapper.getUriFromActionMapping(am));
+        assertEquals("view/456/article/123", mapper.getUriFromActionMapping(am));
     }
 
     public void testGetMappingNoSlash() throws Exception {