本文介绍了ADF af:inputFile不会使用valueChangeListener触发ValueChangeEvent的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试将RichInputFile与viewScopeBean绑定失败.

I am unsucessfuly trying to bind a RichInputFile with a viewScopeBean.

这是我的代码:

jsff:

<af:panelGroupLayout id="pgl1" layout="horizontal">
      <af:inputFile label="Upload File" id="if1"
                    binding="#{viewScope.userBean.inputFile}"
                    valueChangeListener="#{viewScope.userBean.onFileUploadValueChangeListener}"
                    autoSubmit="true"/>
      <af:spacer width="10" height="10" id="s7"/>
      <af:commandButton text="Upload" id="cb1"
                        disabled="#{viewScope.userBean.inputFile.value == null ? true : false}"
                        partialTriggers="if1"
                        actionListener="#{viewScope.userBean.onUploadFile}"/>
  </af:panelGroupLayout>

bean:

public class UserBean{
private RichInputFile inputFile;
private UploadedFile file;
private String fileContent;
private String fileName;
private InputStream inputstream;

public UserBean() {
    super();
}

public void onFileUploadValueChangeListener(ValueChangeEvent valueChangeEvent) {
    resetValue();
    file = (UploadedFile)valueChangeEvent.getNewValue();
    try {
        inputstream = file.getInputStream();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

public void onUploadFile(ActionEvent actionEvent) {
    if (file != null && inputstream != null) {
        fileName = file.getFilename();
        StringWriter writer = new StringWriter();

    }
    if (inputFile != null) {
        inputFile.resetValue();
        inputFile.setValid(true);
    }
}

public void resetValue() {
    if (fileName != null)
        fileName = null;
    if (fileContent != null)
        fileContent = null;
    if (inputstream != null)
        inputstream = null;
}

public void setInputFile(RichInputFile inputFile) {
    this.inputFile = inputFile;
}

public RichInputFile getInputFile() {
    return inputFile;
}

public void setFile(UploadedFile file) {
    this.file = file;
}

public UploadedFile getFile() {
    return file;
}

public String getFileContent() {
    return fileContent;
}

public String getFileName() {
    return fileName;
}
}

当我在上载文件元素上选择一个文件时,将选择该文件,但不会触发ValueChangeEvent,也不会调用onFileUploadValueChangeListener. PPR发生,并且RichInputFile inputFile值仍为null,在屏幕上显示未选择文件". (绑定成功)

When i select a file on the upload file element, the file is selected but the ValueChangeEvent is not trigger and the onFileUploadValueChangeListener is not called. PPR occur and the RichInputFile inputFile value is still null, displaying "No file selected" on the screen. (the binding is successfull)

我应该如何纠正在af:inputFile上触发valueChangeEvent的问题?

What should i correct to have the valueChangeEvent triggered on an af:inputFile ?

推荐答案

我找到了答案.

要触发af:inputFile valueChangeEvent,必须将其用af:formUsesUpload ="true"标记包围:

To have the af:inputFile valueChangeEvent triggered it is mandatory to have it surround by a af:form usesUpload="true" tag :

<af:panelGroupLayout id="pgl1" layout="horizontal">
 <af:form usesUpload="true" id="f1">
  <af:inputFile label="Upload File" id="if1"
                binding="#{viewScope.userBean.inputFile}"
                valueChangeListener="#{viewScope.userBean.onFileUploadValueChangeListener}"
                autoSubmit="true"/>
  <af:spacer width="10" height="10" id="s7"/>
  <af:commandButton text="Upload" id="cb1"
                    disabled="#{viewScope.userBean.inputFile.value == null ? true : false}"
                    partialTriggers="if1"
                    actionListener="#{viewScope.userBean.onUploadFile}"/>
  </af:form>
</af:panelGroupLayout>

这篇关于ADF af:inputFile不会使用valueChangeListener触发ValueChangeEvent的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-21 12:02