【问题标题】:Primefaces advanced FileUpload with MobileRenderKit使用 MobileRenderKit 的 Primefaces 高级文件上传
【发布时间】:2015-08-28 02:26:11
【问题描述】:

Advanced FileUpload 是否适用于 MobileRenderKit?

我尝试使用以下代码上传:

上传.xhtml:

   <h:form  enctype="multipart/form-data"
      rendered="#{eordner.uploadaktiv}">
      <p:fileUpload id="dateiupload" fileUploadListener="#{upload.getfiles}">
      </p:fileUpload>
      <p:commandButton value="Hochladen..." />
   </h:form>

上传bean.java:

  public void getfiles(FileUploadEvent event) {

      System.out.println(event.getFile().getFileName());

   }

但 fileUploadListener 从未被调用。

当我更改为正常的 RenderKit 时,它会被调用。

有解决办法吗?我希望能够进行多次上传。

简单模式运行良好

我在 Primefaces 5.2 番茄 7.0.26 Java 1.0.7 莫哈拉 2.2.10

谢谢

【问题讨论】:

  • 简单模式可以正常工作,但只适用于一个文件
  • 在 PF Mobile 6 中,高级模式仍然不会调用它的侦听器。如果被按钮激活,它只是重定向回页面而不调用按钮的 ActionListener。此外,简单模式似乎无法验证必填字段、文件大小和扩展名。

标签: jsf mobile primefaces primefaces-mobile


【解决方案1】:

看一下PF移动端FileUpload源代码:

protected void encodeInputField(FacesContext context, FileUpload fileUpload, String clientId) throws IOException {
    ResponseWriter writer = context.getResponseWriter();

    writer.startElement("input", null);
    writer.writeAttribute("data-role", "none", null);
    writer.writeAttribute("type", "file", null);
    writer.writeAttribute("name", clientId, null);

    if(fileUpload.isMultiple()) writer.writeAttribute("multiple", "multiple", null);
    if(fileUpload.getStyle() != null) writer.writeAttribute("style", fileUpload.getStyle(), "style");
    if(fileUpload.getStyleClass() != null) writer.writeAttribute("class", fileUpload.getStyleClass(), "styleClass");
    if(fileUpload.isDisabled()) writer.writeAttribute("disabled", "disabled", "disabled");

    writer.endElement("input");
}

,表示不支持高级模式,但multiple属性支持。

所以试试multiple="true"

【讨论】:

  • 谢谢,但使用 multiple="true" 我可以选择多个文件,但只能上传第一个文件
猜你喜欢
  • 2012-02-07
  • 2017-03-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-03-19
  • 1970-01-01
  • 2014-10-06
相关资源
最近更新 更多