2013-05-30 14 views
0

我試圖用<a4j:commandButton>在bean中調用一個簡單的動作方法。但是,當我使用rendereddisabled屬性(也從操作方法評估)時,它不起作用。<a4j:commandButton>不調用動作

這裏是我的代碼片段:

<a4j:region block="true" > 
    <a4j:form id="download_form"> 
     <a4j:commandButton id="download_button" 
      action="#{studentInfo.actionDownload}" 
      onclick="#{rich:component('download_progress')}.show(); setPopupPosition('#{rich:clientId('download_progress')}');" 
      reRender="dlod_msg_grd" 
      oncomplete="#{rich:component('download_progress')}.hide(); 
      value="Download a student" 
      rendered="#{studentInfo.validForDownload}" 
      /> 
    </a4j:form> 
</a4j:region> 

如果我使用rendered="#{studentInfo.validForDownload}"rendered="#{true}"這一切工作正常,bean的操作方法得到了調用。但我現在使用的方式不起作用

studentInfo.validForDownload正在評估爲true,因此a4j:commandButton正在呈現正確。

+0

'studentInfo'託管bean的範圍是什麼? –

+0

@LuiggiMendoza,它在請求範圍 – Switch

+0

看起來你的'studentInfo.validForDownload'字段的默認值是'false'。嘗試在'studentInfo'類定義上添加'@ KeepAlive'註釋,例如'@KeepAlive公共類StudentIfo {...}'。 –

回答

1

由於您的studentInfo託管bean具有請求範圍,正如您在對Luiggi的響應中所述,rendered="#{studentInfo.validForDownload}"將始終評估爲默認值。以及由Luiggi提到的,​​你必須爲了獲得所需的行爲使用a4j:keepAlive,但在你的代碼稍加改動:

<a4j:keepAlive beanName = "studentInfo"/> 
<h:form id="download_form"> 
    <a4j:region block="true" > 
    <a4j:commandButton id="download_button" 
     action="#{studentInfo.actionDownload}" 
     onclick="#{rich:component('download_progress')}.show(); setPopupPosition('#{rich:clientId('download_progress')}');" 
     reRender="dlod_msg_grd" 
     oncomplete="#{rich:component('download_progress')}.hide(); 
     value="Download a student" 
     rendered="#{studentInfo.validForDownload}"/> 
    </a4j:region> 
</h:form> 

我不知道,如果a4j:form有效果,但可以肯定的h:form將工作

+0

試過那個,但得到這個錯誤。 必須是文字 – Switch

+0

啊,我很抱歉,請嘗試:

+0

這也沒有奏效。獲取NotSerializable異常。有沒有一種方法可以將設置的值保留爲默認值。 – Switch