What's going on?
What you get is correct behaviour. In PrimeFaces button with type="button" works as it does in basic HTML - it doesn't cause any request. As PrimeFaces user's guide says:
Push buttons are used to execute custom javascript without causing an
ajax/non-ajax request. To create a push button set type as "button".
<p:commandButton type="button" value="Alert" onclick="alert('Prime')" />
If you want to "talk to" bean, you need to use type="submit" (which is default in p:commandButton).
However... contrary to submit buttons behaviour in HTML, in PrimeFaces such submission will not force redirection to new page but all communication will be handled by underlying AJAX requests.
Therefore only your second button will execute beans' method:
<p:commandButton id="s" value="submit" action="#{andreBean.runSubmit}" />
What probably you wanted to obtain?
If you don't want to send all your form to bean you can limit the scope of components that are processed with "process" attribute of p:commandButton:
<h:form id="test">
<p:inputText value="#{andreBean.value}"/>
<p:commandButton id="s" value="submit" action="#{andreBean.runSubmit}" process="@this" />
</h:form>
With the following bean you will see the difference:
public class AndreBean {
private String value;
public void runSubmit() {
System.out.println("Submit executed");
}
public String getValue() {
System.out.println("getValue");
return value;
}
public void setValue(String value) {
System.out.println("setValue: " + value);
this.value = value;
}
}
If you don't limit executed components in console you get:
getValue
setValue: foobar
Submit executed
...and with components limited only to process="@this" you get only:
Submit executed
Hope that helps.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…