【问题标题】:Wicket getCallbackURL method doesn't work as expectedWicket getCallbackURL 方法无法按预期工作
【发布时间】:2014-03-19 10:19:38
【问题描述】:

我已将我的应用程序迁移到 wicket 6.14,并在文件上传字段中尝试使用以下实现获取文件名和文件大小

@Override
            public CharSequence getCallbackUrl() {
                CharSequence callBackUrl = super.getCallbackUrl();
                //File attribute of file input type is supported by certain browsers therefore conditionally returns the file size using js
                return callBackUrl +
                        "&filename=' + this.value + '&filesize=' + (function(undefined) {if($(\"<input type='file'>\").get(0).files !== undefined){ return $('#fileInput')[0].files[0].size}else{return 0;}})() + '";//"&filename=' + this.value + '";//
            }

但是当我尝试读取参数值时,它会返回 this,文件名的值和 jquery 函数的文件大小。

Request request = RequestCycle.get().getRequest();
                String filename = findFileName(request.getRequestParameters().getParameterValue("filename").toString());
                String fileSize = request.getRequestParameters().getParameterValue("filesize").toString();

我该怎么做?

【问题讨论】:

  • FileUploadField 中没有 getCallbackUrl() 方法。请描述您要覆盖的类以及您如何使用它。这是一种行为吗?

标签: javascript file-upload wicket


【解决方案1】:

评估 js 以获取文件大小并随后从请求中读取它是没有意义的。此时文件已经存在,您可以直接访问它。

解决方案的一个提示:覆盖getAttributes() 并添加一个新的IAjaxCallListener。您可以在那里评估 js 并将文件大小放在隐藏文件中(或检查 getPrecondition() 中的文件大小,如果文件太大则返回 false)。

【讨论】:

    【解决方案2】:

    这个答案可能有助于更清洁的检票口 6 方式。

    https://stackoverflow.com/a/23555297/463918

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-04-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-07
      • 2021-04-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多