JSF动态包括使用Ajax请求 [英] JSF dynamic include using Ajax request
问题描述
在JSF2,是有可能改变的用户界面的src值:包括使用Ajax请求(例如像PrimeFaces号码:的commandButton)动态? 谢谢你。
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>
这就是我现在所拥有的。是否有可能使阿贾克斯(使用号码:的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一个基本的例子,否则你确实需要使用&LT; F:&setPropertyActionListener GT;
就像在你的问题):
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屋!