Author: ivaynberg
Date: Wed Dec 16 23:21:47 2009
New Revision: 891469

URL: http://svn.apache.org/viewvc?rev=891469&view=rev
Log:
WICKET-2621
Issue: WICKET-2621

Modified:
    
wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/markup/html/form/Form.java
    
wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/markup/html/form/upload/MultiFileUploadField.java
    
wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/protocol/http/servlet/MultipartServletWebRequest.java
    
wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/util/tester/FormTester.java

Modified: 
wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/markup/html/form/Form.java
URL: 
http://svn.apache.org/viewvc/wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/markup/html/form/Form.java?rev=891469&r1=891468&r2=891469&view=diff
==============================================================================
--- 
wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/markup/html/form/Form.java
 (original)
+++ 
wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/markup/html/form/Form.java
 Wed Dec 16 23:21:47 2009
@@ -385,7 +385,10 @@
        private Bytes maxSize = null;
 
        /** True if the form has enctype of multipart/form-data */
-       private boolean multiPart = false;
+       private short multiPart = 0;
+
+       private static short MULTIPART_HARD = 0x01;
+       private static short MULTIPART_HINT = 0x02;
 
        /**
         * Constructs a form with no validation.
@@ -1135,7 +1138,14 @@
         */
        public void setMultiPart(boolean multiPart)
        {
-               this.multiPart = multiPart;
+               if (multiPart)
+               {
+                       this.multiPart |= MULTIPART_HARD;
+               }
+               else
+               {
+                       this.multiPart &= ~MULTIPART_HARD;
+               }
        }
 
        /**
@@ -1603,7 +1613,7 @@
 
        private boolean isMultiPart()
        {
-               if (multiPart)
+               if (multiPart != 0)
                {
                        return true;
                }
@@ -1615,7 +1625,7 @@
 
                                public Object component(Form<?> form)
                                {
-                                       if (form.multiPart)
+                                       if (form.multiPart != 0)
                                        {
                                                anyEmbeddedMultipart[0] = true;
                                                return STOP_TRAVERSAL;
@@ -1991,6 +2001,9 @@
        @Override
        protected void onRender(final MarkupStream markupStream)
        {
+               // clear multipart hint, it will be set if necessary by the 
visitor
+               this.multiPart &= ~MULTIPART_HINT;
+
                // Force multi-part on if any child form component is multi-part
                visitFormComponents(new FormComponent.AbstractVisitor()
                {
@@ -1999,7 +2012,7 @@
                        {
                                if (formComponent.isVisible() && 
formComponent.isMultiPart())
                                {
-                                       setMultiPart(true);
+                                       multiPart |= MULTIPART_HINT;
                                }
                        }
                });

Modified: 
wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/markup/html/form/upload/MultiFileUploadField.java
URL: 
http://svn.apache.org/viewvc/wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/markup/html/form/upload/MultiFileUploadField.java?rev=891469&r1=891468&r2=891469&view=diff
==============================================================================
--- 
wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/markup/html/form/upload/MultiFileUploadField.java
 (original)
+++ 
wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/markup/html/form/upload/MultiFileUploadField.java
 Wed Dec 16 23:21:47 2009
@@ -193,9 +193,13 @@
                        throw new IllegalStateException("Component " + 
getClass().getName() + " must have a " +
                                Form.class.getName() + " component above in the 
hierarchy");
                }
-               form.setMultiPart(true);
        }
 
+       @Override
+       public boolean isMultiPart()
+       {
+               return true;
+       }
 
        /**
         * @see 
org.apache.wicket.markup.html.IHeaderContributor#renderHead(org.apache.wicket.markup.html.IHeaderResponse)

Modified: 
wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/protocol/http/servlet/MultipartServletWebRequest.java
URL: 
http://svn.apache.org/viewvc/wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/protocol/http/servlet/MultipartServletWebRequest.java?rev=891469&r1=891468&r2=891469&view=diff
==============================================================================
--- 
wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/protocol/http/servlet/MultipartServletWebRequest.java
 (original)
+++ 
wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/protocol/http/servlet/MultipartServletWebRequest.java
 Wed Dec 16 23:21:47 2009
@@ -110,7 +110,8 @@
                final boolean isMultipart = 
ServletFileUpload.isMultipartContent(request);
                if (!isMultipart)
                {
-                       throw new IllegalStateException("ServletRequest does 
not contain multipart content");
+                       throw new IllegalStateException(
+                               "ServletRequest does not contain multipart 
content. One possible solution is to explicitly call Form.setMultipart(true), 
Wicket tries its best to auto-detect multipart forms but there are certain 
situation where it cannot.");
                }
 
 

Modified: 
wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/util/tester/FormTester.java
URL: 
http://svn.apache.org/viewvc/wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/util/tester/FormTester.java?rev=891469&r1=891468&r2=891469&view=diff
==============================================================================
--- 
wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/util/tester/FormTester.java
 (original)
+++ 
wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/util/tester/FormTester.java
 Wed Dec 16 23:21:47 2009
@@ -678,7 +678,7 @@
                {
                        Field multiPart = 
Form.class.getDeclaredField("multiPart");
                        multiPart.setAccessible(true);
-                       return multiPart.getBoolean(workingForm);
+                       return multiPart.getShort(workingForm) != 0;
                }
                catch (SecurityException e)
                {


Reply via email to