A preRender listener is always called in the pre render event, whether it is an initial request or a postback request. Each individual request has a rendering response stage, regardless of whether it is a regular request or an ajax request. Therefore, this behavior is determined by the specification. You need to check yourself in the listener method if it is a reverse request or not by checking FacesContext#isPostback() .
public void sendComment() { if (!FacesContext.getCurrentInstance().isPostback()) {
<f:event type="preRenderXxx"> (where Xxx can be View or Component ), in fact, is a "workaround" to the functional requirement that the bean action method can be called after the viewing parameters are processed upon initial request. In the upcoming JSF 2.2, a new <f:viewAction> tag will be introduced, which should perform the task as intentional:
<f:viewAction action="#{newsBean.sendComment}" />
This tag supports the onPostback attribute, which defaults to false :
<f:viewAction action="#{newsBean.sendComment}" onPostback="false" />
JSF 2.2 will be released in the first quarter of 2012. JSF 2.2 snapshot releases are now available.
source share