I'm using JBoss Wildfly 8.2.0 and noticed that <f:viewParam>
is called twice on my page:
- The first time is when I access my page with the given param in the URL
- The second time is upon the first AJAX request I make from that page
Bean:
@Named
@javax.faces.view.ViewScoped
public class MessageBean implements Serializable {
private String message;
private int count;
public String getMessage() {
return message;
}
public void setMessage(String message) {
System.out.println("setting message");
this.message = message;
}
public void increment() {
this.count++;
}
public int getCount() {
return count;
}
}
XHTML:
<!DOCTYPE html ...>
<html ...>
<f:metadata>
<f:viewParam name="message" value="#{messageBean.message}" />
</f:metadata>
<h:head>
<title>Message</title>
</h:head>
<h:body>
<h:form>
<h:outputText value="#{messageBean.message} (#{messageBean.count} time(s))" />
<h:commandButton value="increment">
<f:ajax render="@form" listener="#{messageBean.increment}" />
</h:commandButton>
</h:form>
</h:body>
</html>
I don't understand why AJAX requests are triggering the <f:viewParam>
and why only the first one.