Wicket - FileUploadField, Ajax and Preview

送分小仙女□ 提交于 2020-01-05 07:13:34

问题


Im using Wicket 1.5 and I need to build a component with a FileUploadField to load an image.

I need an Ajax behaviour to make a preview of image after selected it (without submiting the entire form).

Searching on Google, I found this Event that match when I select the file:

AjaxEventBehavior choose = new AjaxEventBehavior("onChange"){
      private static final long serialVersionUID = 1L;
      @Override
      protected void onEvent(AjaxRequestTarget target) {
        Request request = RequestCycle.get().getRequest();
      }
};

What I need is the stream of image to put in a little panel that required:

byte[] imgBytes

And obviously I need the same stream to fill a PropertyModel for DB storing.

Thanks


回答1:


You need to use either AjaxFormSubmitBehavior (will submit the entire form on the given event) or AjaxFormComponentUpdatingBehavior (will submit only the one form component. I'm not sure whether the latter works with file uploads, just give it a try. You can always use the former.

In the model of your FileUploadField you will find a (list of) FileUpload - look at the methods you get, there are input streams and other things available so you can do pretty much anything with the data.



来源:https://stackoverflow.com/questions/12260092/wicket-fileuploadfield-ajax-and-preview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!