简体   繁体   English

Primefaces 6:禁用按钮,使用fileUpload组件以简单模式上传

[英]Primefaces 6: disable button Upload with fileUpload component with mode simple

I'm using Primefaces 6 and I create a fileUpload component as below: 我正在使用Primefaces 6,并创建了一个fileUpload组件,如下所示:

                <p:fileUpload id="myId" 
                          styleClass="MY-STYLE" 
                          value="#{bean.objUploadedFile}" 
                          mode="simple" 
                          skinSimple="true" 
                          multiple="false"
                          update="@form"
                          label="Choose"
            >
            </p:fileUpload>

I must use mode=simple so ajax is false. 我必须使用mode=simple所以ajax是false。 I add then a button to manage the upload: 然后添加一个按钮来管理上传:

                <p:commandButton id="btnId" 
                             value="Upload" 
                             disabled="#{myBean.btnDisabled}"
                             process="@form"
                             update="@form"
                             ajax="false"
                             actionListener="#{myBean.manageUpload}" 
            />

This button is loaded with disable=true to startup. 此按钮加载有disable=true才能启动。 Can I set disable=false for this button when user click on Choose button in the fileUpload component? 当用户单击fileUpload组件中的“选择”按钮时,可以为此按钮设置disable=false吗? I tried with javascript but it does not work. 我尝试使用javascript,但无法正常工作。 Is it possible? 可能吗?

Unfortunately it's not possible, I tried and discovered that fileUpload is a "non-ClientBehaviorHolder parent" (aka. no p:ajax ). 不幸的是,这是不可能的,我尝试并发现fileUpload是“ non-ClientBehaviorHolder父对象”(又名p:ajax)。

The second option would be use one of the java script events of the generated input type="file" ( https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file ), but prime faces do not expose then... 第二个选项是使用生成的输入type =“ file”( https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file )的Java脚本事件之一,但是素面不暴露...

Wich means the jsf - prime faces way, at least in simple mode, is to let the button always enable and validate file selection on form submit. Wich表示jsf-prime face方法(至少在简单模式下)是让按钮始终启用并验证表单提交时的文件选择。

Although if you really want/need enable the button on file selection, you can use jquery to attach a event listener to the input type="file" that will enable the button, but this option is kinda of hack, so I don't recomend it because prime-faces and jsf tend to be unforgiving when you mess around with their expected component behaviors. 尽管如果您确实希望/需要在文件选择上启用按钮,则可以使用jquery将事件监听器附加到将启用按钮的输入type =“ file”上,但是此选项有点hack,所以我不推荐它,因为当您混淆它们的预期组件行为时,prime-faces和jsf往往不会原谅。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM