ajax - Richfaces 使用 a4j 呈现 :ajax

标签 ajax jsf richfaces rendering

我有一个使用 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>

命令按钮的 Action 代码是:

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 的东西。

干杯,

最佳答案

我终于做到了!

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

我只是渲染(重新渲染?)只是 processLabel 和表单总是在那里,因为我没有更新 View (我认为这必须与 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 保持不变。

干杯!!!

关于ajax - Richfaces 使用 a4j 呈现 :ajax,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9121279/

相关文章:

JSF 1.2 应用程序无法与 GlassFish v3 配合使用

javascript - 使用 Ajax 调用将数组传递到 Javascript 代码中

javascript - 使用 jQuery concat 添加新行

css - IE8 和 Primefaces p :selectOneMenu misbehave when having a lots of p:selectOneMenu in a form

java - 由 : java. lang.ArrayIndexOutOfBoundsException 引起:数组索引超出范围:0

java - 如何使 jsf @ManagedBean 也成为 @WebService

javascript - 在 JSF 中,我如何理解多复选框是否全部选中?

javascript - 如何启用所有经过身份验证的路由以显示 Devise ajax 登录表单?

java - 如何在Ajax成功方法中打开Spring ModelAndView响应作为一个完整的页面

tomcat - Servlet Faces Servlet 不可用(richfaces 4、tomcat 7)