2012-02-02 77 views
3

我有一个页面,使用rich:fileUploada4j:commandButton我想实现的是,第一次加载页面fileUpload出现(被呈现,我的backingBean默认为真,所以它呈现正确),当用户点击命令按钮我很想隐藏文件上传和显示的outputText(这是不会发生,没有错误可言)Richfaces渲染与a4j:ajax

我怎样才能解决这个问题,我pagelooks像

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

UPDATE 基本上我想要的是上传文件的用户的当在用户点击按钮的FileUpload组件自败和的outputText出现,说什么“谢谢上传”

也许我的方法是错误的,只是把我放在正确的方向,我有点混淆与Ajax的东西。

干杯,

+0

如果尝试rerender =“processLabel”而不是render =“processLabel” – HRgiger 2012-02-02 23:05:39

+0

a4j:commandButton没有任何'reRender'属性。我与richfaces 4.1和Mojarra 2.1.6和Tomcat – BRabbit27 2012-02-02 23:07:44

+0

我认为它支持我使用的cas。请检查http://stackoverflow.com/a/2243473/706695或http://docs.jboss.org/ richfaces/latest_3_3_X/en/devguide/html/a4j_commandButton.html#6.1.6.2。%20Details%20of%20Usage – HRgiger 2012-02-02 23:19:20

回答

2

最后我做到了!

这是代码,所以你可以看到修改。 基本上我不得不处理整个表格(execute="@form"),其中a4j:commandButton已经做了,然后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> 

支持bean保持不变。

干杯!

相关问题