The action and actionlistener of <p:commandButton> are not called when <p:inputText> is added.
Here’s my view:
<?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://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:body>
<h:form>
<h:outputText value="Respuesta" />
<p:inputText
required="true"
value=" #{respuestaOficioBean.mrString}"/>
<p:commandButton
action="#{respuestaOficioBean.clearRespuesta}"
actionListener= "#{respuestaOficioBean.listener}"
update="growl"
value="s ss ssssssss ss ssszzs #{respuestaOficioBean.respuesta}"/>
<p:growl id="growl" showDetail="false" sticky="true" />
</h:form>
</h:body>
</html>
Here’s my bean:
private String mrString;
public String getMrString() {
return mrString;
}
public void setMrString(String mrString) {
this.mrString = mrString;
}
public String clearRespuesta() {
setRespuesta(new RespuestaOficio());
return null;
}
public void listener (ActionEvent event) {
System.out.println("uuu");
}
If I remove the <p:inputText> from the view, then “uuu” is printed and the breakpoint in clearRespuesta() is invoked. However if I leave the <p:inputText>, none of the former happens.
How is this caused and how can I solve it?
I didn’t immediately see the cause of your problem, so I copypasted your code into my environment (which has the OmniFaces
FullAjaxExceptionHandlerconfigured) and I got an error page with the following rather self-explaining stacktrace:This was also visible in the server log.
The cause of your problem is a dangling leading space in the
valueattribute of the<p:inputText>. This is invalid syntax for a setter method call.Remove it:
In the future pay a bit more attention to the server log and the response body of the ajax request (which you can see in the HTTP traffic monitor of the webbrowser’s developer toolset). The error information was visible in there.