2016-04-08 28 views
0

我尝试更新按钮单击页面的一部分。 现在,我有以下几点:p:commandButton刷新整个页面,而不是部分,而f:ajax正常工作

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

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

那么,内容已经更新,但页面刷新。有什么想法我在这里做错了吗?

+0

你对页面的意思是什么意思?重装上阵?或者你是否放弃了范围? – tak3shi

+2

停止使用'prependId =“false”',只是从不使用它,这是JSF 1.2中的一个不良后果。 – BalusC

回答

0

我终于解决了。

我在我的Button上使用了一个actionListener。

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

的包括源正在从一个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"; 
} 

在页面加载的currentObject仍然是空所以显示news.xhtml。点击后,当前设置为一个对象,页面更新到详细信息页面。全部没有重新加载页面。

0

您没有调用任何有效的AJAX动作:

删除action="index",以避免重新加载索引页。

+0

如果这是答案,它仍然是奇怪的......一个工程,另一个不...... – Kukeltje

+0

删除按钮上的动作=“索引”只是导致按钮什么都不做。 index是包含内容的xhtml文件,它应该更新。 – user1882509

+0

使用p:commandButton,您默认执行ajax请求。这不需要采取任何行动。您已选择更新newsContent。如果什么都没有发生,那你应该检查你是否需要用actionListener调用一些代码来准备你想要看到的改变。 – tak3shi

相关问题