2016-04-08 71 views
0

我嘗試更新按鈕單擊頁面的一部分。 現在,我有以下幾點:p:commandButton刷新整個頁面,而不是部分,而f:ajax正常工作

的template.xhtml

<h:form prependId="false"> 

     <h:commandButton value="NEWS" action="news"> 
      <f:ajax render="newsContent"></f:ajax> 
     </h:commandButton> 

     <h:panelGroup layout="block" id="newsContent"> 
      <ui:insert name="newsContent"> 
       <ui:include src="/WEB-INF/partials/news/news.xhtml"/> 
      </ui:insert> 
     </h:panelGroup> 

    </h:form> 

/WEB-INF/partials/news/news.xhtml

<h:commandLink action="newsdetails"> 
    <f:ajax render="newsContent" /> 
</h:commandLlink> 

newsdetails.xhtml

<h:commandButton value="INDEX" action="index"> 
    <f:ajax render="newsContent" /> 
</h:commandButton> 

現在它工作正常,但如果我的東西替換<h:commandbutton>

<p:commandButton value="INDEX" action="index" update="newsContent"/> 

那麼,內容已經更新,但頁面刷新。有什麼想法我在這裏做錯了嗎?

+0

你對頁面的意思是什麼意思?重裝上陣?或者你是否放棄了範圍? – tak3shi

+2

停止使用'prependId =「false」',只是從不使用它,這是JSF 1.2中的一個不良後果。 – BalusC

回答

0

我終於解決了。

我在我的Button上使用了一個actionListener。

<p:commandLink actionListener="#{news.setCurrent(n)}" update="newsContent" /> 

的包括源正在從一個Bean閱讀:

<h:panelGroup layout="block" id="newsContent"> 
    <ui:insert name="newsContent"> 
     <ui:include src="#{news.page}"/> 
    </ui:insert> 
</h:panelGroup> 

而且頁面的吸氣器看起來像:

public String getPage() { 
    if(current == null){ 
     return "/WEB-INF/partials/news/news.xhtml"; 
    } 
    return "/WEB-INF/partials/news/details.xhtml"; 
} 

在頁面加載的currentObject仍然是空所以顯示news.xhtml。點擊後,當前設置爲一個對象,頁面更新到詳細信息頁面。全部沒有重新加載頁面。

0

您沒有調用任何有效的AJAX動作:

刪除action="index",以避免重新加載索引頁。

+0

如果這是答案,它仍然是奇怪的......一個工程,另一個不...... – Kukeltje

+0

刪除按鈕上的動作=「索引」只是導致按鈕什麼都不做。 index是包含內容的xhtml文件,它應該更新。 – user1882509

+0

使用p:commandButton,您默認執行ajax請求。這不需要採取任何行動。您已選擇更新newsContent。如果什麼都沒有發生,那你應該檢查你是否需要用actionListener調用一些代碼來準備你想要看到的改變。 – tak3shi

相關問題