0

I have simplified everything to just two files as below:

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

And the backing 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 */
}

The problem is: after I pressed the second p:commandButton (Save), the first p:commandButton (search) does not invoke the bean method (traced by tomcat log output).

I traced the XMLHttpRequest and found that in the failed requests, the request header lacks javax.faces.ViewState:-3177489149850736864:913391262441057407. The ajax response is normal - rendering the p:dataTable, only with no results.

Pressing the h:commandButton works. I am not sure whether it is a Primefaces bug or there is something that I missed. I prefer sticking to Primefaces buttons to maintain the same look and feel throughout my app.

cpliu338
  • 645
  • 1
  • 7
  • 20
  • I believe your problem points to 4th point of the answer by Balusc in this link http://stackoverflow.com/questions/2118656/hcommandlink-hcommandbutton-is-not-being-invoked – Srikanth Ganji Mar 13 '14 at 08:13
  • @SrikanthGanji : That's not his problem, his `p:commandButton` is neither in `p:dataTable` or `ui:repeat`. – Kishor Prakash Mar 13 '14 at 08:32
  • Did you try without `process="@form"`? – Mathew Rock Mar 13 '14 at 08:48
  • Add @this also along with the ids to commandButtons process attribute to invoke the action on p:commandButton. This is mandatory. For clear insight see this http://stackoverflow.com/questions/5699088/what-is-the-function-of-this-exactly – Srikanth Ganji Mar 13 '14 at 09:26
  • @KishorP There is a commandButton in p:datatable but there is no action associated with it. My point would have been valid if action associated with it. :) – Srikanth Ganji Mar 13 '14 at 09:28
  • try `` or `` – Nomade Mar 13 '14 at 10:16
  • Thanks folks for your comments. But 1) as Kishor pointed out, the p:commandButton in question is not in a p:dataTable or ui:repeat; 2) h:commandButton works but not p:commandButton, so Primefaces must have implemented it differently. – cpliu338 Mar 13 '14 at 13:25
  • For ease of reference, I have edited and simplified the post – cpliu338 Mar 14 '14 at 03:24

0 Answers0