p:commandButton在调用另一个操作后不调用操作

时间:2014-03-13 07:24:47

标签: java ajax jsf primefaces

我已将所有内容简化为两个文件,如下所示:

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://xmlns.jcp.org/jsf/core"
  xmlns:p="http://primefaces.org/ui" xmlns:h="http://xmlns.jcp.org/jsf/html"
  xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
<h:head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link href="#{facesContext.externalContext.requestContextPath}/resources/css/default.css" rel="stylesheet" type="text/css" />
    <link href="#{facesContext.externalContext.requestContextPath}/resources/css/cssLayout.css" rel="stylesheet" type="text/css" />
    <title>Secure</title>
</h:head>
<h:body>
    <h:form id="form1">
        <p:inputText id="crit" value="#{publisherBean.crit}"/>
        <p:commandButton process="@form" update="data" icon="ui-icon-search" action="#{publisherBean.search()}"/>
        <p:dataTable id="data" value="#{publisherBean.foundPublishers}" var="pub">
            <p:column>
                <h:outputText value="#{pub}"/>
            </p:column>
        </p:dataTable>
    </h:form>
    <h:form id="form2">
        <p:commandButton action="#{publisherBean.save()}" value="Save" update=":form1 @form" />
        <h:commandButton action="#{publisherBean.save()}" value="Save">
            <f:ajax execute="@form" render=":form1 @form"/>
        </h:commandButton>
    </h:form>
</h:body>
</html>

支持bean:

@ManagedBean
@ViewScoped
public class PublisherBean {
private ArrayList<String> foundPublishers;
private String crit;
private String publisher;

public PublisherBean() {
    foundPublishers = new ArrayList<>();
}
public void save() {    
    crit = "";
    foundPublishers.clear();
}
public void search() {
    foundPublishers.clear();
    foundPublishers.add("Dummy 1");
}
/* Getters and Setters */
}

问题是:在我按下第二个p:commandButton(保存)之后,第一个p:commandButton(搜索)没有调用bean方法(由tomcat日志输出跟踪)。

我跟踪XMLHttpRequest并发现在失败的请求中,请求标头缺少javax.faces.ViewState:-3177489149850736864:913391262441057407。 ajax响应是正常的 - 渲染p:dataTable,但没有结果。

按h:commandButton可以正常工作。我不确定它是Primefaces的错误还是我错过了什么。我更喜欢坚持使用Primefaces按钮在我的应用程序中保持相同的外观和感觉。

0 个答案:

没有答案