FileUploadField constructor in wicket 6

254 views Asked by At

I have an issue with FileUploadField constructor. I think I traveled in time. So after migration into wicket 6 this constructor is no longer possible:

FileUploadField uploadField = new FileUploadField("browseFile", new Model<FileUpload>());

After removing new Model<FileUpload>() I got known error:

Caused by: org.apache.wicket.WicketRuntimeException: No get method defined for class: class pl.thetis.beans.service.TicketComplete expression: browseFile

I noticed that second constructor is

public FileUploadField(final String id, IModel<List<FileUpload>> model)
{
    super(id, model);
}

Unfortunetly I have no idea how to create this.

I came up with this solution but I think its nasty one

List list = new LinkedList<FileUpload>(); 
FileUploadField uploadField = new FileUploadField("browseFile", new Model<FileUpload>().ofList(list));

If I declare list as List<FileUpload> it doesn't work.

1

There are 1 answers

1
martin-g On BEST ANSWER

Try with new FileUploadField("browseFile", new ListModel<FileUpload>(yourList));.

It uses a List now so it is possible to use HTML5 <input type="file" multiple>, i.e. you can upload several files at once with modern browsers.