문제

I have a wicket form that has a file upload box on it. Sometimes this file upload box is hidden because the user isn't required to attach documentation. I have called setMultiPart(true) on the form object, but I still (but only rarely) get this error:

java.lang.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.

Helpful facts:

  • This form gets submitted about 10,000 times per day and I get this error 5-10 times per day.
  • If the user that got the error fills out the form again with the same data it will work fine.
  • I have never been able to replicate the error locally at all.
  • The few users that I have talked to that have received this error say that they were not uploading a file.

Here is the condensed version of the form code:

Form<MyObject> form = new Form<MyObject>("form")
{       
        @Override
        protected void onSubmit()
        {
        //saving stuff here
        }

        @Override
        protected void onValidate()
        {
            super.onValidate();
            //This just highlights the fields on the form:
            visitChildren( FormComponent.class, new FormValidationVisitor() );
        }
}       

add(form);
form.setMultiPart(true);
form.setMaxSize(Bytes.kilobytes( 5120 ));

There is a custom Validator added to the form and there are some AJAX callbacks to some of the form fields, but the form itself isn't AJAXy. Looking at the generated source in the browser I get the form declaration looking like this:

form id="form4a" action="../wicket/page?12-1.IFormSubmitListener-form" encType="multipart/form-data" method="post" accept-charset="UTF-8"

The button that submits the form is a standard wicket Button on the Java side and an input type="submit" on the HTML side, although in the browser source view I do see a jQuery18307179054977115189="23" attribute on the input.

Any ideas? I've tried every which way just to replicate this bug and cannot so ANY help you can give would be great. I am using Wicket 6.6.0.

도움이 되었습니까?

해결책

I had the same problem just few minutes ago. Inside the outer form, I have a nested form for file upload component. So, here is how I fixed: My outer and inner forms both have setMultipart(true) and it works as expected.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top