Strange Behaviour with p:commandButton usage

UI Components for JSF
Post Reply
g.prajeesh77
Posts: 9
Joined: 08 Oct 2011, 06:03
Location: Bangalore, India

02 Apr 2012, 09:30

Hi,

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;
    }

}
xhtml file

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>
is it the desired behavior?
Primeface 3.2/Apache Tomcat-7.0.19/Mojarra 2.1.7 (SNAPSHOT 20120206)

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 23 guests