weixin_33698043 2012-02-02 22:57 采纳率: 0%
浏览 76

Richfaces使用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)

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:

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.

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"

Maybe my approach is wrong, just put me in the right direction, I'm kind of confuse with the ajax stuff.

Cheers,

  • 写回答

1条回答 默认 最新

  • weixin_33697898 2012-02-03 00:14
    关注

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

    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)

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

    Cheers!!!

    评论

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?