2011-10-12 42 views
1

我想製作一個正在處理ajax的網頁(所有的ajax)。我的意思是,只要你點擊一個鏈接(我指的是< h:outputLink ...>),使用另一個鏈接的數據改變某個div。如何ajax jsf 2輸出鏈接

例如:

<ui:composition template="/layout.xhtml"> 
    <ui:define name="main"> 
     //my content here 
    </ui:define> 
</ui:composition> 

這是可能的:

<h:outputLink value="/page.jsf" onclick="myfunction(this); return false;"> 
    My page 
</h:outputLink> 

page.jsf是一種正常的JSF頁面...使用頁面layout.xhtml希望顯示? 這是可能的,使用servlet從一個特定的jsf只採取片段?

我最後的解決方案是使用jquery.load功能...

問候

回答

4

<h:link><h:outputLink>不能Ajax化。所有的JSF2 ajax請求都是根據規範的POST請求。你需要一個<h:form><h:commandLink>

你可以使用下面的結構:

<h:form> 
    <f:ajax render=":include"> 
     <h:commandLink value="Home" action="#{menuManager.setPage('home')}" /><br /> 
     <h:commandLink value="FAQ" action="#{menuManager.setPage('faq')}" /><br /> 
     <h:commandLink value="Contact" action="#{menuManager.setPage('contact')}" /><br /> 
    </f:ajax> 
</h:form> 
<h:panelGroup id="include"> 
    <ui:include src="#{menuManager.page}.xhtml" /> 
</h:panelGroup> 
+0

謝謝你..我會盡力的... – Alex

+1

威爾F:AJAX元素上包含的頁面(例如home.xhtml)工作? – chzbrgla