Commits

Anonymous committed c603753

only 3 tests failing now (got the FormTag working by doing some refactoring)

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

  • Participants
  • Parent commits 8c2f7d2

Comments (0)

Files changed (9)

src/java/com/opensymphony/webwork/views/jsp/ui/AbstractClosingUITag.java

 
     public int doStartTag() throws JspException {
         try {
+            evaluateParams(getValueStack());
             String openTemplateName = buildTemplateName(getOpenTemplate(), getDefaultOpenTemplate());
             mergeTemplate(openTemplateName);
         } catch (Exception e) {

src/java/com/opensymphony/webwork/views/jsp/ui/AbstractListTag.java

         return false;
     }
 
-    void evaluateParams(OgnlValueStack stack) {
+    public void evaluateExtraParams(OgnlValueStack stack) {
         if (listAttr != null) {
             addParam("list", MakeIterator.convert(stack.findValue(listAttr)));
         }

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

     }
 
     public int doEndTag() throws JspException {
-        HttpServletRequest req = (HttpServletRequest) pageContext.getRequest();
-        OgnlValueStack stack = (OgnlValueStack) req.getAttribute("webwork.valueStack");
-        if (stack == null) {
-                stack = new OgnlValueStack();
-                HttpServletResponse res = (HttpServletResponse) pageContext.getResponse();
-                Map extraContext = ServletDispatcher.createContextMap(req.getParameterMap(),
-                        new SessionMap(req.getSession()),
-                        new ApplicationMap(pageContext.getServletContext()),
-                        req,
-                        res,
-                        pageContext.getServletConfig());
-                extraContext.put(ServletActionContext.PAGE_CONTEXT, pageContext);
-                stack.getContext().putAll(extraContext);
-                req.setAttribute("webwork.valueStack", stack);
-            }
+        OgnlValueStack stack = getValueStack();
+        evaluateParams(stack);
+
+        try {
+            mergeTemplate(this.getTemplateName());
+
+            return EVAL_BODY_INCLUDE;
+        } catch (Exception e) {
+            LOG.error("Could not generate UI template", e);
+
+            return SKIP_BODY;
+        }
+    }
 
+    protected void evaluateParams(OgnlValueStack stack) {
         Object name = null;
         if (nameAttr != null) {
             name = stack.findValue(nameAttr, String.class);
 
         if (valueAttr != null) {
             addParam("value", stack.findValue(valueAttr, String.class));
-        } else {
+        } else if (name != null) {
             addParam("value", stack.findValue(name.toString(), String.class));
         }
 
-        evaluateParams(stack);
-
-        try {
-            mergeTemplate(this.getTemplateName());
-
-            return EVAL_BODY_INCLUDE;
-        } catch (Exception e) {
-            LOG.error("Could npt generate UI template", e);
+        evaluateExtraParams(stack);
+   }
 
-            return SKIP_BODY;
-        }
+    protected void evaluateExtraParams(OgnlValueStack stack) {
     }
 
-    void evaluateParams(OgnlValueStack stack) {
+    protected OgnlValueStack getValueStack() {
+        HttpServletRequest req = (HttpServletRequest) pageContext.getRequest();
+        OgnlValueStack stack = (OgnlValueStack) req.getAttribute("webwork.valueStack");
+        if (stack == null) {
+            stack = new OgnlValueStack();
+            HttpServletResponse res = (HttpServletResponse) pageContext.getResponse();
+            Map extraContext = ServletDispatcher.createContextMap(req.getParameterMap(),
+                    new SessionMap(req.getSession()),
+                    new ApplicationMap(pageContext.getServletContext()),
+                    req,
+                    res,
+                    pageContext.getServletConfig());
+            extraContext.put(ServletActionContext.PAGE_CONTEXT, pageContext);
+            stack.getContext().putAll(extraContext);
+            req.setAttribute("webwork.valueStack", stack);
+        }
+        return stack;
     }
 
     public int doStartTag() throws JspException {

src/java/com/opensymphony/webwork/views/jsp/ui/FormTag.java

  * @author Jason Carreira
  * Created Apr 1, 2003 8:19:47 PM
  */
-public class FormTag extends AbstractClosingUITag implements IterationRenderer {
+public class FormTag extends AbstractClosingUITag {
     //~ Static fields/initializers /////////////////////////////////////////////
 
     final public static String OPEN_TEMPLATE = "form.vm";
 
     //~ Instance fields ////////////////////////////////////////////////////////
 
-    String action;
-    String enctype;
-    String method;
+    String actionAttr;
+    String enctypeAttr;
+    String methodAttr;
 
     //~ Methods ////////////////////////////////////////////////////////////////
 
     public void setAction(String action) {
-        /**
-         * If called from a JSP, pageContext will not be null.  otherwise, we'll get request and response from the
-         * ServletActionContext.
-         *
-         * todo - determine if there's any reason we can't just always use ServletActionContext
-         */
-        HttpServletResponse response = null;
-        HttpServletRequest request = null;
-
-        if (pageContext != null) {
-            response = (HttpServletResponse) pageContext.getResponse();
-            request = (HttpServletRequest) pageContext.getRequest();
-        } else {
-            request = ServletActionContext.getRequest();
-            response = ServletActionContext.getResponse();
-        }
-
-        String result = UrlHelper.buildUrl(action, request, response, null);
-        this.action = result;
-    }
-
-    public String getAction() {
-        return action;
+        this.actionAttr = action;
     }
 
     public String getDefaultOpenTemplate() {
     }
 
     public void setEnctype(String enctype) {
-        this.enctype = enctype;
-    }
-
-    public String getEnctype() {
-        return enctype;
+        this.enctypeAttr = enctype;
     }
 
     public void setMethod(String method) {
-        this.method = method;
-    }
-
-    public String getMethod() {
-        return method;
+        this.methodAttr = method;
     }
 
-    public int doAfterRender(Context context, Writer writer) {
-        return IterationRenderer.RENDER_DONE;
-    }
-
-    public void doBeforeRender(Context context, Writer writer) {
-        //this.evaluateActualValue();
-
-        try {
-            String openTemplate = this.getOpenTemplate();
-
-            if (openTemplate == null) {
-                openTemplate = OPEN_TEMPLATE;
+    public void evaluateExtraParams(OgnlValueStack stack) {
+        super.evaluateExtraParams(stack);
+
+        if (actionAttr != null) {
+            /**
+             * If called from a JSP, pageContext will not be null.  otherwise, we'll get request and response from the
+             * ServletActionContext.
+             *
+             * todo - determine if there's any reason we can't just always use ServletActionContext
+             */
+            HttpServletResponse response = null;
+            HttpServletRequest request = null;
+
+            if (pageContext != null) {
+                response = (HttpServletResponse) pageContext.getResponse();
+                request = (HttpServletRequest) pageContext.getRequest();
+            } else {
+                request = ServletActionContext.getRequest();
+                response = ServletActionContext.getResponse();
             }
 
-            String templateName = buildTemplateName(templateAttr, openTemplate);
-
-            Template template = velocityEngine.getTemplate(templateName);
-            template.merge(context, writer);
-        } catch (Exception e) {
-            try {
-                writer.write("<pre>");
-                e.printStackTrace(new PrintWriter(writer));
-                writer.write("</pre>");
-            } catch (IOException e1) {
-                // ok
+            Object actionObj = stack.findValue(actionAttr, String.class);
+            if (actionObj != null) {
+                String result = UrlHelper.buildUrl(actionObj.toString(), request, response, null);
+                addParam("action", result);
             }
         }
-    }
 
-    /**
-     * Clears all the instance variables to allow this instance to be reused.
-     */
-    public void release() {
-        super.release();
-        method = null;
-        enctype = null;
-        action = null;
+        if (enctypeAttr != null) {
+            addParam("enctype", stack.findValue(enctypeAttr, String.class));
+        }
+
+        if (methodAttr != null) {
+            addParam("method", stack.findValue(methodAttr, String.class));
+        }
     }
 
     protected String getDefaultTemplate() {

src/java/com/opensymphony/webwork/views/jsp/ui/TextFieldTag.java

         this.sizeAttr = size;
     }
 
-    void evaluateParams(OgnlValueStack stack) {
+    public void evaluateExtraParams(OgnlValueStack stack) {
         if (sizeAttr != null) {
             addParam("size", stack.findValue(sizeAttr, String.class));
         }

src/java/com/opensymphony/webwork/views/jsp/ui/TextareaTag.java

         this.rowsAttr = rows;
     }
 
-    void evaluateParams(OgnlValueStack stack) {
+    public void evaluateExtraParams(OgnlValueStack stack) {
         if (colsAttr != null) {
             addParam("cols", stack.findValue(colsAttr, String.class));
         }

src/java/templates/xhtml/form.vm

 <table>
-<form #if ( ${tag.name})name="${tag.name}"#end action="${tag.action}" #if ( ${tag.method})method="${tag.method}"#end #if ( ${tag.enctype})enctype="${tag.enctype}"#end>
+<form
+    #if ($parameters.name)      name="$parameters.name"       #end
+    #if ($parameters.action)    action="$parameters.action"   #end
+    #if ($parameters.method)    method="$parameters.method"   #end
+    #if ($parameters.enctype)   enctype="$parameters.enctype" #end
+>

src/test/com/opensymphony/webwork/views/jsp/ui/FormTagTest.java

 
         FormTag tag = new FormTag();
         tag.setPageContext(pageContext);
-        tag.setName("myForm");
-        tag.setMethod("POST");
-        tag.setAction("myAction");
-        tag.setEnctype("myEncType");
+        tag.setName("'myForm'");
+        tag.setMethod("'POST'");
+        tag.setAction("'myAction'");
+        tag.setEnctype("'myEncType'");
 
         tag.doStartTag();
         tag.doEndTag();

src/test/com/opensymphony/webwork/views/jsp/ui/Formtag-1.txt

 <table>
-<form name="myForm" action="myAction" method="POST" enctype="myEncType">
+<form name="myForm" action="myAction" method="POST" enctype="myEncType" >
 </form>
 </table>