Search in sources :

Example 1 with MultiFileUploadField

use of org.apache.wicket.markup.html.form.upload.MultiFileUploadField in project wicket by apache.

the class FormTester method setFile.

/**
 * Sets the <code>File</code> on a {@link FileUploadField}.
 *
 * @param formComponentId
 *            relative path (from <code>Form</code>) to the selectable
 *            <code>FormComponent</code>. The <code>FormComponent</code> must be of a type
 *            <code>FileUploadField</code>.
 * @param file
 *            the <code>File</code> to upload or {@code null} for an empty input
 * @param contentType
 *            the content type of the file. Must be a valid mime type.
 * @return This
 */
public FormTester setFile(final String formComponentId, final File file, final String contentType) {
    checkClosed();
    FormComponent<?> formComponent = (FormComponent<?>) workingForm.get(formComponentId);
    MockHttpServletRequest servletRequest = tester.getRequest();
    if (formComponent instanceof FileUploadField) {
        servletRequest.addFile(formComponent.getInputName(), file, contentType);
    } else if (formComponent instanceof MultiFileUploadField) {
        String inputName = formComponent.getInputName() + MultiFileUploadField.MAGIC_SEPARATOR + multiFileUploadIndex++;
        servletRequest.addFile(inputName, file, contentType);
    } else {
        fail("'" + formComponentId + "' is not " + "a FileUploadField. You can only attach a file to form " + "component of this type.");
    }
    return this;
}
Also used : FormComponent(org.apache.wicket.markup.html.form.FormComponent) MultiFileUploadField(org.apache.wicket.markup.html.form.upload.MultiFileUploadField) MockHttpServletRequest(org.apache.wicket.protocol.http.mock.MockHttpServletRequest) MultiFileUploadField(org.apache.wicket.markup.html.form.upload.MultiFileUploadField) FileUploadField(org.apache.wicket.markup.html.form.upload.FileUploadField)

Aggregations

FormComponent (org.apache.wicket.markup.html.form.FormComponent)1 FileUploadField (org.apache.wicket.markup.html.form.upload.FileUploadField)1 MultiFileUploadField (org.apache.wicket.markup.html.form.upload.MultiFileUploadField)1 MockHttpServletRequest (org.apache.wicket.protocol.http.mock.MockHttpServletRequest)1