ADF af:inputFile不会使用valueChangeListener触发ValueChangeEvent

时间:2016-03-16 10:07:40

标签: jsf oracle-adf

我无法尝试将RichInputFile与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值仍为空,显示&#34;未选择文件&#34;屏幕上。 (绑定成功)

如果在af:inputFile?

上触发valueChangeEvent,我应该更正

2 个答案:

答案 0 :(得分:3)

我找到了anwser。

要使af:inputFile valueChangeEvent触发,必须让它由af:form usesUpload =“true”标签包围:

<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>

答案 1 :(得分:0)

如果我们在任务流区域上有一个表单并且 usesUpload="true" 它也可以工作吗??

是的。

如果您在任务流区域上有一个表单,您应该找到 usesUpload="true" 并将其添加到该表单中。它将添加到允许您上传文件的 html: enctype="multipart/form-data" 中,并且 valueChangeListener 将被捕获。