簡體   English   中英

Richfaces使用a4j渲染:ajax

[英]Richfaces render with a4j:ajax

我有一個頁面使用rich:fileUploada4j:commandButton我想要實現的是,第一次加載頁面時會出現fileUpload(渲染,我的backingBean默認為true,因此它呈現正確)並且當用戶點擊commandButton我很想隱藏fileUpload並顯示一個outputText (這沒有發生,根本沒有錯誤)

我怎么能解決這個問題,我的網頁看起來像

    <div id="content">
        <a4j:outputPanel id="contentForm">
            <h:form enctype="multipart/form-data"
                    rendered="#{uploadBean.formRendered}">

                <br/><br/>

                <h:selectOneRadio value="#{uploadBean.selectedOption}">
                    <f:selectItems value="#{uploadBean.loadOptions}"/>
                </h:selectOneRadio>

                <br/>

                <rich:fileUpload addLabel="Agregar" clearAllLabel="Quitar todos"
                                 clearLabel="Quitar" deleteLabel="Quitar"
                                 doneLabel="Completado" uploadLabel="Subir archivos"
                                 fileUploadListener="#{uploadBean.doUpload}"
                                 acceptedTypes="txt, csv"
                                 noDuplicate="true"/>

                <a4j:commandButton value="Iniciar validación"
                                   action="#{uploadBean.doLaunchProcess}"
                                   render="processLabel"
                                   execute="@form"
                                   />

            </h:form>
        </a4j:outputPanel>
        <a4j:outputPanel id="processLabel">
            <h:outputText
                value="#{uploadBean.processStarted}"
                rendered="#{not uploadBean.formRendered}"/>
        </a4j:outputPanel>
    </div>

而commandButton的動作代碼是:

public String doLaunchProcess() {
    formRendered = false;
    InfoValidator iv = new InfoValidator(loadOptions, 
            selectedOption, userBean.getDependencia(), 
            userBean.getTipoDependencia(), userBean.getUsuario(),
            userBean.getIdUsuario(), userBean.getEmail());
    iv.start();
    return "carga-archivos";
}

似乎formRendered總是被評估為true,當我希望一旦用戶單擊該按鈕它為false,所以fileUpload隱藏並顯示outputText。

更新基本上我想要的是當用戶點擊按鈕時用戶上傳文件,fileUpload組件消失並出現outputText,並說“謝謝上傳”

也許我的方法是錯的,只是把我放在正確的方向,我有點混淆ajax的東西。

干杯,

最后我做到了!

這是代碼,因此您可以看到修改。 基本上我必須處理整個表單( execute="@form" ),其中a4j:commandButton已經然后render="contentForm :processLabel"

我只是渲染(reRendering?)只是processLabel而且表單始終存在'因為我沒有更新視圖(我認為這必須是DOM樹,有人請澄清這個)

    <div id="content">
        <a4j:outputPanel id="contentForm">
            <h:form enctype="multipart/form-data"
                    rendered="#{uploadBean.formRendered}">

                <br/><br/>

                <h:selectOneRadio value="#{uploadBean.selectedOption}">
                    <f:selectItems value="#{uploadBean.loadOptions}"/>
                </h:selectOneRadio>

                <br/>

                <rich:fileUpload addLabel="Agregar" clearAllLabel="Quitar todos"
                                 clearLabel="Quitar" deleteLabel="Quitar"
                                 doneLabel="Completado" uploadLabel="Subir archivos"
                                 fileUploadListener="#{uploadBean.doUpload}"
                                 acceptedTypes="txt, csv"
                                 noDuplicate="true"/>

                <a4j:commandButton value="Iniciar validación"
                                   action="#{uploadBean.doLaunchProcess}"
                                   render="contentForm :processLabel"/>

            </h:form>
        </a4j:outputPanel>
        <a4j:outputPanel id="processLabel">
            <h:outputText
                value="#{uploadBean.processStarted}"
                rendered="#{not uploadBean.formRendered}"/>
        </a4j:outputPanel>
    </div>

支持bean保持不變。

干杯!!!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM