2012-02-02 76 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保持不變。

乾杯!

相關問題