Pergunta

I am trying to get FileUpload from fileupload field on 'onChange' event in wicket. But it is always giving null after selecting a file. My code looks like this,

fileUploadField.add(new AjaxEventBehavior("onChange") {
    @Override
    protected void onEvent(AjaxRequestTarget target) {
        FileUpload fileUpload = fileUploadField.getFileUpload();
        if(fileUpload!=null) {
            //my code
        }
    }
}

I also tried with AjaxFormComponentUpdatingBehavior("onChange").

Please help me.

Foi útil?

Solução

The FileUpload is really null using AJAX call, because file upload is processing in following steps.

  1. Choose file in a form field
  2. Post the form using HTTP POST request
  3. Receive the HTTP POST request on the server side
  4. Parse the request to a the FileUpload

If you just add an onChange ajax event on your file input field it causes just a GET request on an URL, but it doesn't send the form data.

You can try OnChangeAjaxBehavior or AjaxButton as shown in examples on http://www.wicket-library.com/wicket-examples/ajax/upload

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top