How to ajax jsf 2 outputLink

自古美人都是妖i 提交于 2019-12-30 11:01:05

问题


I want to make a webpage that is working on ajax(everything ajax). I mean.. whenever you click a link(I refer to < h:outputLink ...> ) to change a certain div using data from another link.

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:

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

My last solution is to use jquery.load function...

Regards


回答1:


<h:link> and <h:outputLink> cannot be ajaxified. All JSF2 ajax requests are per specification POST requests. You need a <h:form> with a <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>


来源:https://stackoverflow.com/questions/7737759/how-to-ajax-jsf-2-outputlink

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!