ADF af:inputFile does not trigger ValueChangeEvent with valueChangeListener

流过昼夜 提交于 2019-12-24 00:46:30

问题


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

Here is my code :

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

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)

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


回答1:


I found the anwser.

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>


来源:https://stackoverflow.com/questions/36032476/adf-afinputfile-does-not-trigger-valuechangeevent-with-valuechangelistener

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!