禁用"Choose"按钮文件在主要面孔中上传



我将fileLimit设置为1。我希望当用户选择第一个文件时,选择按钮被禁用。

我解决了在fileUpload中放入一个禁用的atribut的问题,该问题与我的bean中的布尔变量类似。当文件完成上传时,变量将其值更改为true,我更新fileUpload组件,然后该组件被禁用。谢谢你们的帮助。

试试这个。

xhtml

<p:fileUpload fileUploadListener="#{fileUploadView.handleFileUpload}" 
              mode="advanced" 
              dragDropSupport="false" 
              update="messages,@this" 
              sizeLimit="100000" 
              fileLimit="1" 
              allowTypes="/(.|/)(gif|jpe?g|png)$/"
              disabled="#{fileUploadView.fileUploadCount >= 1}"/>
<p:growl id="messages" showDetail="true" />   

管理

@ManagedBean
public class FileUploadView {
    private int fileUploadCount;
    public int getFileUploadCount() {
        return fileUploadCount;
    }
    public void setFileUploadCount(int fileUploadCount) {
        this.fileUploadCount = fileUploadCount;
    }
    public void handleFileUpload(FileUploadEvent event) {
        FacesMessage msg = new FacesMessage("Succesful", event.getFile().getFileName() + " is uploaded.");
        FacesContext.getCurrentInstance().addMessage(null, msg);
        fileUploadCount = fileUploadCount + 1;
    }
}

这是一个易于修改的文件限制。当你想更改文件限制为2时,你只需更改CCD_ 1和CCD_。

相关内容

最新更新