2013-03-13 30 views
0

嗨,我們正在使用a4j標記。<h:commandButton>在動作後不刷新頁面

在這裏,我們正在從數據庫檢索數據後點擊一下按鈕。即使數據在服務器中可用,它也不會在視圖中顯示。手動刷新網頁後會導致數據顯示。

這裏是代碼片段 ....這裏的一些代碼

<rich:tab id="menu5" label="Recall"> 
    <ui:include src="/pages/mctrans/reCallMcifTrans.xhtml" /> 
    </rich:tab> 

reCallMcifTrans.xhtml包含下面的代碼

<h:commandButton type="button" id="reCallbutton1" value=" Search " 
    styleClass="commandExButton"> 
    <a4j:support event="onclick" id="ajsf12" 
     oncomplete="javascript:alert('Search Completed');javascript:document.body.style.cursor='default';" 
     action="#{mcifRecallTransBean.reCallSearch}" reRender="reCallgrid1" /> 
</h:commandButton> 
+0

您的bean的範圍是什麼?有沒有在網址中獲取參數? – 2013-03-13 10:03:28

+0

Bean範圍是會話級別。傳遞搜索參數 – user2164684 2013-03-13 10:15:33

回答

0

當你使用bean裏面請求參數,你需要再次通過他們的行動:

<h:commandButton type="button" id="reCallbutton1" value="Search" styleClass="commandExButton"> 
    <a4j:support event="onclick" id="ajsf12" oncomplete="javascript:alert('Search Completed');javascript:document.body.style.cursor='default';" action="#{mcifRecallTransBean.reCallSearch}" reRender="reCallgrid1" /> 
    <f:param name="param1" value="#{param['param1']}" /> 
    <f:param name="param2" value="#{param['param2']}" /> 
</h:commandButton> 
1

看起來你正在使用RichFaces 3.3。因此,您不需要<h:commandButton<a4j:support>,因爲您可以使用已經完成此操作的<a4j:commandButton>。您可以重構代碼以這樣的:

<a4j:commandButton type="button" id="reCallbutton1" value="Search" 
    styleClass="commandExButton" 
    action="#{mcifRecallTransBean.reCallSearch}" 
    reRender="reCallgrid1" 
    oncomplete="javascript:alert('Search Completed');javascript:document.body.style.cursor='default';" /> 

確保您reCallgrid1組件可用在<a4j:commandButton>相同<h:form>

既然你也想加入等待,而搜索數據行爲單擊按鈕時,您可以使用<a4j:status><a4j:commandButton>一起如圖所示<a4j:status> demo。這裏有一個簡單的例子:

<a4j:commandButton type="button" id="reCallbutton1" value="Search" 
    styleClass="commandExButton" 
    action="#{mcifRecallTransBean.reCallSearch}" 
    reRender="reCallgrid1" /> 
<!-- Note that there's no oncomplete in this case --> 
<a4j:status for="reCallbutton1"> 
    <f:facet name="start"> 
     <h:graphicImage value="/res/images/wait.gif"/> 
    </f:facet> 
</a4j:status> 

最後但並非最不重要,你應該切換您的託管bean要求範圍和使用RichFaces強大<a4j:keepAlive>爲了模擬JSF 2 @ViewScoped。您甚至可以在您的託管bean上使用註釋形式(無需額外配置):

@KeepAlive 
public class McifRecallTransBean { 
    //managed bean code here... 
}