JSF 动态包含使用 Ajax 请求 [英] JSF dynamic include using Ajax request

查看:25
本文介绍了JSF 动态包含使用 Ajax 请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 JSF2 中,是否可以使用 Ajax 请求(例如 PrimeFaces p:commandButton)动态更改 ui:include 的 src 值?谢谢.

In JSF2, is it possible to change the of value of src of ui:include dynamically using Ajax request (like for example PrimeFaces p:commandButton)? Thank you.

<h:form>                        
    <h:commandLink value="Display 2" action="#{fTRNav.doNav()}">
        <f:setPropertyActionListener target="#{fTRNav.pageName}" value="/disp2.xhtml" />
    </h:commandLink>
</h:form>

<ui:include src="#{fTRNav.pageName}"></ui:include>

这就是我现在所拥有的.是否可以使其成为 Ajax(使用 p:commandButton)?

That's what I have right now. Is it possible to make it Ajax (using p:commandButton)?

推荐答案

在另一个答案中提出的 JSTL 标记不是必需的,并且不能很好地重用.

The JSTL tags as proposed in the other answer are not necessary and it is not nicely reuseable.

这是一个使用纯 JSF 的基本示例(假设您运行 Servlet 3.0/EL 2.2,否则您确实需要使用 <f:setPropertyActionListener> 就像您的问题一样):

Here's a basic example using pure JSF (assuming that you runs Servlet 3.0 / EL 2.2, otherwise you indeed need to use <f:setPropertyActionListener> like as in your question):

<h:form>
    <f:ajax render=":include">
        <h:commandLink value="page1" action="#{bean.setPage('page1')}" />
        <h:commandLink value="page2" action="#{bean.setPage('page2')}" />
        <h:commandLink value="page3" action="#{bean.setPage('page3')}" />
    </f:ajax>
</h:form>

<h:panelGroup id="include">
    <ui:include src="#{bean.page}.xhtml" />
</h:panelGroup>

private String page;

@PostConstruct
public void init() {
    this.page = "page1"; // Ensure that default is been set.
}

// Getter + setter.

这篇关于JSF 动态包含使用 Ajax 请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆