[英]Render p:commandButton after uploading a file p:fileUpload
我有一個帶有p:fileUpload和p:commandButton的頁面,第一次訪問該頁面時,該按鈕應該被隱藏,並且在上傳文件后應該呈現該按鈕。 我的代碼如下所示,關於如何實現這一點的任何想法?
<h:form enctype="multipart/form-data" >
<p:fileUpload
fileUploadListener="#{fileUploadController.handleFileUpload}"
mode="advanced"
multiple="true"
sizeLimit="2000000000"
allowTypes="/(\.|\/)(txt|csv)$/"
required="true"
label="Seleccionar"
uploadLabel="Subir a servidor"
cancelLabel="Cancelar">
</p:fileUpload>
<p:commandButton id="btnValidar" value=" Validar "
rendered="#{fileUploadController.btnRendered}"
style="margin-left: 430px;"/>
</h:form>
只需使用update
屬性,就像在所有其他PrimeFaces ajax組件上一樣。
<p:fileUpload update="@form" />
我當然假設你在handleFileUpload
方法中設置了btnRendered
為true
。
請注意,您無法將其設置為按鈕本身的ID,因為當btnRendered
默認為false
時,它不會出現在HTML DOM樹中。 它就是JavaScript,它根據檢索到的Ajax響應在HTML DOM樹中執行更新作業。 如果要單獨更新按鈕而不是表單,請將其包裝在HTML DOM樹中始終存在的另一個組件中:
<h:panelGroup id="btnValidar">
<p:commandButton rendered="#{fileUploadController.btnRendered}" />
</h:panelGroup>
並按如下方式更新
<p:fileUpload update="btnValidar" />
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.