I have noticed the following behavior with p: commandButton. It called the getter Method 3 times while rendering the response. If I used h:commandButton instead of p:commandButton, it calls the getter method only one time.
here is my code piece
Code: Select all
package request.mbeans;
import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import lifecycle.listeners.MyLifecycleListener;
import org.apache.log4j.Logger;
@ManagedBean(name="ManageBean1")
@RequestScoped
public class ManageBean1 implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
private String forward="Forward";
private String redirect="Redirect";
public static Logger logger = Logger.getLogger(ManageBean1.class
.getName());
public ManageBean1() {
super();
logger.debug("Created instance of ManageBean1");
}
public String doNavigation()
{
return "result";
}
public String getForward() {
if (logger.isTraceEnabled()) {
logger.trace("Entering getForward");
}
return forward;
}
public void setForward(String forward) {
if (logger.isTraceEnabled()) {
logger.trace("Entering setForward");
}
this.forward = forward;
}
public String getRedirect() {
if (logger.isTraceEnabled()) {
logger.trace("Entering getRedirect");
}
return redirect;
}
public void setRedirect(String redirect) {
if (logger.isTraceEnabled()) {
logger.trace("Entering setRedirect");
}
this.redirect = redirect;
}
}
Code: Select all
<!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:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ft="http://primefaces.org/facestrace"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title>Page1</title>
</h:head>
<h:body>
<h:form>
<p:panel>
<p:panelGrid columns="2">
<p:commandButton action="#{ManageBean1.doNavigation()}"
value="#{ManageBean1.forward}" ajax="false" />
</p:panelGrid>
</p:panel>
<h:outputLink value="../index.jsp">Home</h:outputLink>
<!-- <ui:debug hotkey="m"></ui:debug> -->
</h:form>
</h:body>
</html>