如何ajax jsf 2 outputLink

Ale*_*lex 2 javascript java ajax jsf-2 jakarta-ee

我想制作一个使用ajax(所有ajax)的网页。我的意思是……每当您单击链接(我指的是 < h:outputLink ...> )以使用来自另一个链接的数据更改某个 div 时。

例如:

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

page.jsf 是一个普通的 jsf 页面......使用页面 layout.xhtml 显示,如:

<ui:composition template="/layout.xhtml">
    <ui:define name="main">
         //my content here
    </ui:define>
</ui:composition>
Run Code Online (Sandbox Code Playgroud)

这可能吗?这可能吗,使用 servlet 只从特定的 jsf 中获取片段?

我的最后一个解决方案是使用 jquery.load 函数...

问候

Bal*_*usC 5

<h:link>并且<h:outputLink>不能被ajaxified。所有 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>
Run Code Online (Sandbox Code Playgroud)