简体   繁体   English

如何ajax jsf 2 outputLink

[英]How to ajax jsf 2 outputLink

I want to make a webpage that is working on ajax(everything ajax). 我想制作一个正在处理ajax的网页(一切都是ajax)。 I mean.. whenever you click a link(I refer to < h:outputLink ...> ) to change a certain div using data from another link. 我的意思是..每当你点击一个链接(我指的是<h:outputLink ...>)来改变某个div时,使用来自另一个链接的数据。

For example: 例如:

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

page.jsf is a normal jsf page... displayed using a page layout.xhtml like: page.jsf是一个普通的jsf页面...使用页面layout.xhtml显示如下:

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

Is this possible? 这可能吗? Is this possible, using a servlet to take only fragments from a specific jsf? 这是可能的,使用servlet只从特定的jsf中获取片段吗?

My last solution is to use jquery.load function... 我的最后一个解决方案是使用jquery.load函数...

Regards 问候

<h:link> and <h:outputLink> cannot be ajaxified. <h:link><h:outputLink>不能被ajaxified。 All JSF2 ajax requests are per specification POST requests. 所有JSF2 ajax请求都是按照规范POST请求。 You need a <h:form> with a <h:commandLink> . 你需要一个带有<h:commandLink><h:form> <h:commandLink>

You could use the following construct: 您可以使用以下构造:

<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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM