简体   繁体   English

Richfaces使用a4j渲染:ajax

[英]Richfaces render with a4j:ajax

I have a page that uses rich:fileUpload and a a4j:commandButton what I want to achieve is, the first time the page is loaded the fileUpload shoul appear(be rendered, my backingBean default is true and so it renders correctly) and when the user hits the commandButton I would love to hide the fileUpload and show an outputText (this is not happening, no error at all) 我有一个页面使用rich:fileUploada4j:commandButton我想要实现的是,第一次加载页面时会出现fileUpload(渲染,我的backingBean默认为true,因此它呈现正确)并且当用户点击commandButton我很想隐藏fileUpload并显示一个outputText (这没有发生,根本没有错误)

How can I solve this, my pagelooks like 我怎么能解决这个问题,我的网页看起来像

    <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>

and the code of the action of the commandButton is: 而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";
}

Is seems that formRendered is always evaluated to true when I want it to be false once a user clicks the button and so the fileUpload hides and show the outputText. 似乎formRendered总是被评估为true,当我希望一旦用户单击该按钮它为false,所以fileUpload隐藏并显示outputText。

UPDATE Basically what I want is the user to upload files an when the user clicks on the button the fileUpload component dissapears and a outputText appears and said something like "Thanks for uploading" 更新基本上我想要的是当用户点击按钮时用户上传文件,fileUpload组件消失并出现outputText,并说“谢谢上传”

Maybe my approach is wrong, just put me in the right direction, I'm kind of confuse with the ajax stuff. 也许我的方法是错的,只是把我放在正确的方向,我有点混淆ajax的东西。

Cheers, 干杯,

Finally I did it ! 最后我做到了!

Here's the code so you can see the modifications. 这是代码,因此您可以看到修改。 Basically I had to process the the whole form ( execute="@form" ) which a4j:commandButton does already and then render="contentForm :processLabel" . 基本上我必须处理整个表单( execute="@form" ),其中a4j:commandButton已经然后render="contentForm :processLabel"

I was only rendering (reRendering?) just the processLabel and the form was always there 'cause I wasn't updating the view (I think this has to be with the DOM tree, someone clarify this please) 我只是渲染(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>

the backing bean remains the same. 支持bean保持不变。

Cheers!!! 干杯!!!

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

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