final FormBean formBean = new FormBean();
   Model<FormBean> model = new Model<FormBean>(formBean);
   Form<FormBean> form = new Form<FormBean>("form", model);

   form.setMultiPart(false);   ---->>>>>>>>>>>>  should be true

   add(form);


François



Le 7 déc. 2010 à 20:45, Cédric Thiébault a écrit :

> It is...
> 
> Here is the code...
> 
> **** HomePage.html
> <html 
> xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.4-strict.dtd";>
>  <body>
> 
>    <div wicket:id="feedback">feedback</div>
> 
>    <form wicket:id="form">
>      Input text: <input type="text" wicket:id="text" size="40" />
>      <br />
>      <div wicket:id="files">files</div>
>      <br />
>      <div wicket:id="modalPanel">modalPanel</div>
>      <div wicket:id="modalPage">modalPage</div>
>      <a wicket:id="showModalPanel">Add new file (panel modal)</a> |
>      <a wicket:id="showModalPage">Add new file (page modal)</a>
>      <br />
>      <br />
>      <input type="submit" wicket:id="submit" value="Submit input text" />
> 
>    </form>
> 
>  </body>
> </html>
> 
> 
> *** UploadPanel.html
> <html xmlns:wicket>
>  <wicket:panel>
> 
>    <div wicket:id="feedback">feedback</div>
> 
>    <form wicket:id="form">
>      File: <input type="file" wicket:id="uploadField" size="40" />
>      <br />
>      <input type="submit" wicket:id="submit" value="Upload" />
>    </form>
> 
>  </wicket:panel>
> </html>
> 
> 
> *** HomePage.java
> public class HomePage extends WebPage {
> 
>  private final transient Logger logger = LoggerFactory.getLogger(getClass());
> 
>  public HomePage() {
> 
>    final FeedbackPanel feedbackPanel = new FeedbackPanel("feedback");
>    add(feedbackPanel);
> 
>    final FormBean formBean = new FormBean();
>    Model<FormBean> model = new Model<FormBean>(formBean);
>    Form<FormBean> form = new Form<FormBean>("form", model);
>    form.setMultiPart(false);
>    add(form);
> 
>    form.add(new TextField<String>("text", new
> PropertyModel<String>(model, "text")));
> 
>    IColumn<String> column = new AbstractColumn<String>(new
> Model<String>("File")) {
>      @Override
>      public void populateItem(Item<ICellPopulator<String>> cellItem,
> String componentId, IModel<String> rowModel) {
>        cellItem.add(new Label(componentId, rowModel));
>      }
>    };
> 
>    final DataTable<String> filesDataTable = new
> DataTable<String>("files", new IColumn[] { column },
>        new ListDataProvider<String>(formBean.getFiles()), 10);
>    filesDataTable.setOutputMarkupId(true);
>    form.add(filesDataTable);
> 
>    final ModalWindow modalPanel = new ModalWindow("modalPanel");
>    modalPanel.setTitle("Upload File");
>    modalPanel.setInitialWidth(500);
>    modalPanel.setInitialHeight(200);
>    form.add(modalPanel);
> 
>    form.add(new AjaxLink<Void>("showModalPanel") {
>      @Override
>      public void onClick(AjaxRequestTarget target) {
>        modalPanel.setContent(new UploadPanel(modalPanel.getContentId()) {
>          @Override
>          protected void onSubmit(@SuppressWarnings("hiding")
> AjaxRequestTarget target, String fileName) {
>            formBean.getFiles().add(fileName);
>            target.addComponent(filesDataTable);
>            modalPanel.close(target);
>          }
>        });
>        modalPanel.show(target);
>      }
>    });
> 
>    final ModalWindow modalPage = new ModalWindow("modalPage");
>    modalPage.setTitle("Upload File");
>    modalPage.setInitialWidth(500);
>    modalPage.setInitialHeight(200);
>    form.add(modalPage);
> 
>    form.add(new AjaxLink<Void>("showModalPage") {
>      @Override
>      public void onClick(AjaxRequestTarget target) {
>        modalPage.setPageCreator(new PageCreator() {
>          @Override
>          public Page createPage() {
>            return new UploadPage() {
>              @Override
>              protected void onSubmit(@SuppressWarnings("hiding")
> AjaxRequestTarget target, String fileName) {
>                formBean.getFiles().add(fileName);
>                target.addComponent(filesDataTable);
>                modalPage.close(target);
>              }
>            };
>          }
>        });
>        modalPage.show(target);
>      }
>    });
> 
>    form.add(new AjaxButton("submit") {
> 
>      @Override
>      protected void onSubmit(AjaxRequestTarget target,
> @SuppressWarnings("hiding") Form<?> form) {
>        logger.info("SUBMIT:");
>        logger.info("text: " + formBean.getText());
>        logger.info("files: " + formBean.getFiles());
>      }
> 
>      @Override
>      protected void onError(AjaxRequestTarget target,
> @SuppressWarnings("hiding") Form<?> form) {
>        target.addComponent(feedbackPanel);
>      }
> 
>    });
> 
>  }
> 
>  public static class FormBean implements Serializable {
> 
>    private String text;
>    private List<String> files = new ArrayList<String>();
> 
>    public String getText() {
>      return text;
>    }
> 
>    public void setText(String text) {
>      this.text = text;
>    }
> 
>    public List<String> getFiles() {
>      return files;
>    }
> 
>    public void setFiles(List<String> files) {
>      this.files = files;
>    }
> 
>  }
> 
> }
> 
> *** UploadPanel.java
> public abstract class UploadPanel extends Panel {
> 
>  private final transient Logger logger = LoggerFactory.getLogger(getClass());
> 
>  public UploadPanel(String id) {
>    super(id);
> 
>    final FeedbackPanel feedbackPanel = new FeedbackPanel("feedback");
>    add(feedbackPanel);
> 
>    Form<?> form = new Form<Void>("form");
>    form.setMultiPart(true);
>    add(form);
> 
>    final FileUploadField uploadField = new
> FileUploadField("uploadField", new Model<FileUpload>());
>    form.add(uploadField);
> 
>    form.add(new AjaxButton("submit") {
> 
>      @Override
>      protected void onSubmit(AjaxRequestTarget target,
> @SuppressWarnings("hiding") Form<?> form) {
>        FileUpload fileUpload = uploadField.getFileUpload();
>        if (fileUpload != null) {
>          String fileName = fileUpload.getClientFileName();
>          logger.info("FILE: " + fileName);
>          UploadPanel.this.onSubmit(target, fileName);
>        } else {
>          error("Unable to upload file.");
>          target.addComponent(feedbackPanel);
>        }
>      }
> 
>      @Override
>      protected void onError(AjaxRequestTarget target,
> @SuppressWarnings("hiding") Form<?> form) {
>        target.addComponent(feedbackPanel);
>      }
> 
>    });
> 
>  }
> 
>  protected abstract void onSubmit(AjaxRequestTarget target, String fileName);
> 
> }
> 
> 
> 
> 
> 
> 
> 2010/12/7 François Meillet <[email protected]>:
>> it has to be in the main form afaik
>> François
>> 
>> Le 7 déc. 2010 à 20:27, Cédric Thiébault a écrit :
>> 
>>> I've done this in the modal window form... And I set it to false for
>>> the main form that is not used for uploading.
>>> The upload works well, it's when my modal is closed, the main form
>>> (not the one for the upload) throws an exception on submit.
>>> 
>>> Here is the code that I've attached to the Jira issue:
>>> http://dl.dropbox.com/u/2167784/wicket-modal-upload.zip
>>> 
>>> Cedric
>>> 
>>> 
>>> 2010/12/7 François Meillet <[email protected]>:
>>>> just add
>>>> form.setMultiPart(true);
>>>> 
>>>> in your form
>>>> 
>>>> François
>>>> 
>>>> Le 7 déc. 2010 à 20:11, Cédric Thiébault a écrit :
>>>> 
>>>>> Hi,
>>>>> 
>>>>> I want to upload files with an Ajax form that is in a modal window
>>>>> (using a Panel, not a WebPage). The modal and its form are part of the
>>>>> main form:
>>>>> 
>>>>> main-page.html
>>>>> <form wicket:id="form">
>>>>>  <div wicket:id="modal" />
>>>>>  <input type="submit" wicket:id="submit" />
>>>>> </form>
>>>>> 
>>>>> upload-window.html
>>>>> <form wicket:id="form">
>>>>>  <input type="file" wicket:id="file" />
>>>>>  <input type="submit" wicket:id="submit" />
>>>>> </form>
>>>>> 
>>>>> 
>>>>> I'm able to upload a file but once the modal is closed, when I submit
>>>>> the main form (not the one for uploading), I get an exception:
>>>>> 
>>>>> 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.
>>>>>     at 
>>>>> org.apache.wicket.protocol.http.servlet.MultipartServletWebRequest.<init>(MultipartServletWebRequest.java:113)
>>>>>     at 
>>>>> org.apache.wicket.protocol.http.servlet.MultipartServletWebRequest.<init>(MultipartServletWebRequest.java:83)
>>>>>     at 
>>>>> org.apache.wicket.protocol.http.servlet.ServletWebRequest.newMultipartWebRequest(ServletWebRequest.java:489)
>>>>>     at 
>>>>> org.apache.wicket.markup.html.form.Form.handleMultiPart(Form.java:1708)
>>>>>     at 
>>>>> org.apache.wicket.markup.html.form.Form.onFormSubmitted(Form.java:886)
>>>>>     at 
>>>>> org.apache.wicket.ajax.form.AjaxFormSubmitBehavior.onEvent(AjaxFormSubmitBehavior.java:135)
>>>>>     at 
>>>>> org.apache.wicket.ajax.AjaxEventBehavior.respond(AjaxEventBehavior.java:177)
>>>>>     at 
>>>>> org.apache.wicket.ajax.AbstractDefaultAjaxBehavior.onRequest(AbstractDefaultAjaxBehavior.java:300)
>>>>>     at 
>>>>> org.apache.wicket.request.target.component.listener.BehaviorRequestTarget.processEvents(BehaviorRequestTarget.java:142)
>>>>>     at 
>>>>> org.apache.wicket.request.AbstractRequestCycleProcessor.processEvents(AbstractRequestCycleProcessor.java:92)
>>>>>     at 
>>>>> org.apache.wicket.RequestCycle.processEventsAndRespond(RequestCycle.java:1250)
>>>>>     at org.apache.wicket.RequestCycle.step(RequestCycle.java:1329)
>>>>>     at org.apache.wicket.RequestCycle.steps(RequestCycle.java:1436)
>>>>>     at org.apache.wicket.RequestCycle.request(RequestCycle.java:545)
>>>>>     at 
>>>>> org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:486)
>>>>>     at 
>>>>> org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.java:319)
>>>>> 
>>>>> 
>>>>> I've created a JIRA issue with code example
>>>>> (https://issues.apache.org/jira/browse/WICKET-3236) but maybe I
>>>>> misunderstood something here...
>>>>> Any help would be appreciated ;-)
>>>>> 
>>>>> Thanks
>>>>> 
>>>>> Cedric
>>>>> 
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: [email protected]
>>>>> For additional commands, e-mail: [email protected]
>>>>> 
>>>> 
>>>> 
>>>> 
>>>> 
>>>> 
>>>> 
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: [email protected]
>>>> For additional commands, e-mail: [email protected]
>>>> 
>>>> 
>>> 
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: [email protected]
>>> For additional commands, e-mail: [email protected]
>>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [email protected]
>> For additional commands, e-mail: [email protected]
>> 
>> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
> 





---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to