2011-10-12 62 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