Wicket-FileUploadField,Ajax和预览 [英] Wicket - FileUploadField, Ajax and Preview

查看:89
本文介绍了Wicket-FileUploadField,Ajax和预览的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Wicket 1.5,我需要使用FileUploadField构建一个组件来加载图像。

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

我需要Ajax行为,以便在选择后进行图像预览

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

在Google上搜索时,我发现该事件与选择文件时相匹配:

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

显然,我需要相同的流来填充PropertyModel进行数据库存储。

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

谢谢

推荐答案

您需要使用 AjaxFormSubmitBehavior (将在给定事件上提交整个表单)或 AjaxFormComponentUpdatingBehavior (将仅提交一个表单组件。我不确定后者是否可用于文件上传,只需尝试一下即可。您始终可以使用前者。

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.

在FileUploadField的模型中,您将找到一个FileUpload(列表)-查看获得的方法,输入流和其他可用的东西,以便您可以对数据做几乎所有的事情。

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.

这篇关于Wicket-FileUploadField,Ajax和预览的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆