p:commandButton刷新整个页面而不是部分刷新,而f:ajax可以正常工作 [英] p:commandButton refreshes entire page instead of partially whereas f:ajax works fine

查看:194
本文介绍了p:commandButton刷新整个页面而不是部分刷新,而f:ajax可以正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在按钮单击时更新页面的一部分. 现在,我有以下内容:

I try to update a part of the page on button click. Right now, I have the following :

template.xhtml

    <h:form prependId="false">

        <h:commandButton value="NEWS" action="news">
            <f:ajax render="newsContent"></f:ajax>
        </h:commandButton>

        <h:panelGroup layout="block" id="newsContent">
            <ui:insert name="newsContent">
                <ui:include src="/WEB-INF/partials/news/news.xhtml"/>
            </ui:insert>
        </h:panelGroup>

    </h:form>

/WEB-INF/partials/news/news.xhtml

<h:commandLink action="newsdetails">
    <f:ajax render="newsContent" />
</h:commandLlink>

newsdetails.xhtml

 <h:commandButton value="INDEX" action="index">
     <f:ajax render="newsContent" />
 </h:commandButton>

现在它可以正常工作,但是如果我将<h:commandbutton>替换为

Right now its working fine, but if I replace the <h:commandbutton> with something like

<p:commandButton value="INDEX" action="index" update="newsContent"/>

然后更新内容,但刷新页面.有什么想法我在这里做错了吗?

Then the content is updated but the page is refreshed. Any thoughts what I am doing wrong here?

推荐答案

我终于解决了.

我在Button上使用了一个actionListener.

I used an actionListener on my Button.

<p:commandLink actionListener="#{news.setCurrent(n)}" update="newsContent" />

现在可以从Bean中读取包含的来源:

The source of the include is now read from a Bean:

<h:panelGroup layout="block" id="newsContent">
    <ui:insert name="newsContent">
        <ui:include src="#{news.page}"/>
    </ui:insert>
</h:panelGroup>

页面的吸气剂类似于:

public String getPage() {
    if(current == null){
        return "/WEB-INF/partials/news/news.xhtml";
    }
    return "/WEB-INF/partials/news/details.xhtml";
}

在Pageload上,currentObject仍然为null,因此显示了news.xhtml.单击后,将当前设置为对象",并将页面更新为详细信息页面.全部都无需重新加载页面.

On Pageload the currentObject is still null so the news.xhtml is shown. After the click the current is set to an Object and the page is updated to the details page. All without a reload of the page.

这篇关于p:commandButton刷新整个页面而不是部分刷新,而f:ajax可以正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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