Commits

jcarreira  committed 8e196d6

WW-480: TokenTag doesn't break when name attribute can't be referenced

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

  • Participants
  • Parent commits 12ae1d1

Comments (0)

Files changed (5)

 webapps
 .classpath
 .project
-build-*
+build-*
+Test Plan.jmx
+Test Plan.jtl
+Test Plan2.jmx
+Test_Results.jtl
+Test Plan.jmx
+Test Plan.jtl
+Test Plan2.jmx
+Test Plan.jmx
+Test Plan2.jmx
+Test Plan.jmx
+Test Plan.jtl
+Test Plan2.jmx

File src/java/com/opensymphony/webwork/views/jsp/ui/AbstractUITag.java

     }
 
     /**
-     * A contract that requires each concrete UI Tag to specify which template should be used as a default.  For
-     * example, the CheckboxTab might return "checkbox.vm" while the RadioTag might return "radio.vm".  This value
-     * <strong>not</strong> begin with a '/' unless you intend to make the path absolute rather than relative to the
-     * current theme.
-     *
-     * @return The name of the template to be used as the default.
-     */
+ * A contract that requires each concrete UI Tag to specify which template should be used as a default.  For
+ * example, the CheckboxTab might return "checkbox.vm" while the RadioTag might return "radio.vm".  This value
+ * <strong>not</strong> begin with a '/' unless you intend to make the path absolute rather than relative to the
+ * current theme.
+ *
+ * @return The name of the template to be used as the default.
+ */
     protected abstract String getDefaultTemplate();
 
     /**
-     * Find the name of the Velocity template that we should use.
-     *
-     * @return The name of the Velocity template that we should use. This value should begin with a '/'
-     */
+ * Find the name of the Velocity template that we should use.
+ *
+ * @return The name of the Velocity template that we should use. This value should begin with a '/'
+ */
     protected String getTemplateName() {
         return buildTemplateName(templateAttr, getDefaultTemplate());
     }
     }
 
     /**
-     * @param myTemplate
-     * @param myDefaultTemplate
-     */
+ * @param myTemplate
+ * @param myDefaultTemplate
+ */
     protected String buildTemplateName(String myTemplate, String myDefaultTemplate) {
         String template = myDefaultTemplate;
 
     }
 
     /**
-     * Finds all ScriptValidationAware validators that apply to the field covered by this tag.
-     *
-     * @param formTag the parent form tag this tag is in
-     * @param fieldName the name of the field to validate (used for error message key)
-     * @param fieldClass the Class of the object the field is for
-     * @param propertyName the actual property name to get validator for; if null, fieldName is used
-     */
+ * Finds all ScriptValidationAware validators that apply to the field covered by this tag.
+ *
+ * @param formTag the parent form tag this tag is in
+ * @param fieldName the name of the field to validate (used for error message key)
+ * @param fieldClass the Class of the object the field is for
+ * @param propertyName the actual property name to get validator for; if null, fieldName is used
+ */
     private void findScriptingValidators(FormTag formTag, String fieldName, Class fieldClass, String propertyName) {
         List validators = ActionValidatorManager.getValidators(fieldClass, formTag.getActionName());
 

File src/java/com/opensymphony/webwork/views/jsp/ui/TokenTag.java

 
 import com.opensymphony.webwork.util.TokenHelper;
 
+import com.opensymphony.xwork.util.OgnlValueStack;
+
+import java.util.Map;
+
 import javax.servlet.http.HttpServletRequest;
-import javax.servlet.jsp.JspException;
 
 
 /**
         return TokenHelper.TOKEN_NAME_FIELD;
     }
 
+    protected String getDefaultTemplate() {
+        return TEMPLATE;
+    }
+
     /**
-     * First looks for the token in the PageContext using the supplied name (or {@link TokenHelper#DEFAULT_TOKEN_NAME}
-     * if no name is provided) so that the same token can be re-used for the scope of a request for the same name. If
-     * the token is not in the PageContext, a new Token is created and set into the Session and the PageContext with
-     * the name.
-     *
-     * @throws JspException
-     */
-    public int doEndTag() throws JspException {
+ * First looks for the token in the PageContext using the supplied name (or {@link TokenHelper#DEFAULT_TOKEN_NAME}
+ * if no name is provided) so that the same token can be re-used for the scope of a request for the same name. If
+ * the token is not in the PageContext, a new Token is created and set into the Session and the PageContext with
+ * the name.
+ *
+ */
+    protected void evaluateExtraParams(OgnlValueStack stack) {
+        super.evaluateExtraParams(stack);
+
         String tokenName = null;
+        Map parameters = getParameters();
 
-        if (nameAttr == null) {
-            tokenName = TokenHelper.DEFAULT_TOKEN_NAME;
+        if (parameters.containsKey("name")) {
+            tokenName = (String) parameters.get("name");
         } else {
-            tokenName = (String) findValue(nameAttr, String.class);
-
-            if (tokenName == null) {
-                tokenName = nameAttr;
+            if (nameAttr == null) {
+                tokenName = TokenHelper.DEFAULT_TOKEN_NAME;
+            } else {
+                tokenName = (String) findValue(nameAttr, String.class);
+
+                if (tokenName == null) {
+                    tokenName = nameAttr;
+                }
             }
-        }
 
-        addParameter("name", tokenName);
+            addParameter("name", tokenName);
+        }
 
         String token = buildToken(tokenName);
         addParameter("token", token);
-
-        return super.doEndTag();
-    }
-
-    protected String getDefaultTemplate() {
-        return TEMPLATE;
     }
 
     private String buildToken(String name) {

File src/test/com/opensymphony/webwork/views/jsp/ui/TokenTagTest.java

         assertEquals(token, anotherToken);
     }
 
+    /**
+     * WW-480
+     */
+    public void testNotFindableName() {
+        String tokenName = "foo";
+        TokenTag tag = new TokenTag();
+        tag.setName(tokenName);
+        doTokenTest(tokenName, tag);
+
+        String s = writer.toString();
+        assertTrue(s.indexOf("name=\"" + TokenHelper.DEFAULT_TOKEN_NAME) > -1);
+        assertTrue(s.indexOf("value=\"" + tokenName + "\"") > -1);
+        assertTrue(s.indexOf("name=\"" + tokenName + "\"") > -1);
+
+        //System.out.println(s);
+    }
+
     public void testSuppliedName() {
         String tokenName = "my.very.long.token.name";
         TokenTag tag = new TokenTag();

File src/webapp/WEB-INF/.cvsignore

 sessions
 tmp
 work
+webwork.tld