【问题标题】:Richfaces render with a4j:ajaxRichfaces 使用 a4j:ajax 渲染
【发布时间】:2012-02-25 15:15:31
【问题描述】:

我有一个使用rich:fileUploada4j:commandButton 的页面我想要实现的是,第一次加载页面时应该出现fileUpload(被渲染,我的backingBean 默认为true,因此它可以正确渲染)当用户点击命令按钮时,我很想隐藏 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 总是被评估为真,当我希望它为假时,一旦用户单击按钮,因此 fileUpload 隐藏并显示 outputText。

更新 基本上我想要的是用户上传文件,当用户点击按钮时,fileUpload 组件消失并且出现 outputText 并说“感谢上传”

也许我的方法是错误的,只是让我朝着正确的方向前进,我对 ajax 的东西有点困惑。

干杯,

【问题讨论】:

标签: ajax jsf richfaces rendering


【解决方案1】:

我终于做到了!

这是代码,您可以查看修改。 基本上我必须处理 a4j:commandButton 已经完成的整个表单 (execute="@form"),然后是 render="contentForm :processLabel"

我只是渲染(重新渲染?)只是 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>

backing bean 保持不变。

干杯!!!

【讨论】:

    猜你喜欢
    • 2012-02-03
    • 1970-01-01
    • 1970-01-01
    • 2012-10-01
    • 1970-01-01
    • 2012-08-03
    • 2011-08-24
    • 2011-03-12
    • 2011-11-26
    相关资源
    最近更新 更多