@ViewScoped loose state and be recreated when I push a button

282 views Asked by At

UPDATE
After comments, I tried to reduce the example code to a minimal part, and (thanks to Balush) I discovered that is not related to the inheritance, neither to jpa or eclipse link. A simple page with two button and one controller that have just one field: the first time I push one button, it does not reload the page and execute the listener, the second time reload the page and the listener is never called Follow the two part of code

partdetails.xhtml

<?xml version='1.0' encoding='UTF-8' ?>
<!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:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core">
    <h:head>
        <title></title>
    </h:head>
    <h:body>

        <h:form id="form">
            <div class="border">
                    <h:outputText value="#{partDetailsController.editing}" />
            </div>
            <h:panelGrid columns="2">
                <f:facet name="footer">
                    <br />
                    <p:commandButton id="btnEditCancel" value="Cancel" update=":form" actionListener="#{partDetailsController.onBtnEditCancelClick}" 
                                      immediate="true" />
                    <p:commandButton id="btnEdit" value="Edit" update=":form" actionListener="#{partDetailsController.onBtnEditClick}" 
                                     style="margin-right: 0.9em;" />
                </f:facet>
            </h:panelGrid>
        </h:form>
    </h:body>
</html>

and the controller (partDetailsController.java)

package test.controllers.views;

import java.io.Serializable;
import java.util.logging.Logger;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.event.ActionEvent;

@ManagedBean
@ViewScoped
//public class PartDetailsController extends PartBaseController implements Serializable
public class PartDetailsController  implements Serializable
{

    private static final long serialVersionUID = 6704867527770742213L;

    private boolean editing = false;
    private static final Logger LOG = Logger.getLogger(PartDetailsController.class.getName());

    /**
     * Costruttore della classe.
     */
    public PartDetailsController()
    {
       LOG.info("constructor");

    }

    @PostConstruct
    public void init()
    {
        LOG.info("init");

    }

    public boolean isEditing()
    {
        return editing;
    }

    public void setEditing(boolean editing)
    {
        this.editing = editing;
    }

    public void onBtnEditClick(ActionEvent event)
    {
        LOG.info("edit pushed, editing value was "+ isEditing());
        editing = true;
    }

    public void onBtnEditCancelClick(ActionEvent event)
    {
        LOG.info("cancel pushed, editing value was "+ isEditing());
        editing = false;
    }

}

The application have an authentication, in web.xml

    <login-config>
        <auth-method>FORM</auth-method>
        <realm-name>ourSecurity</realm-name>
        <form-login-config>
            <form-login-page>/login.xhtml</form-login-page>
            <form-error-page>/permissiondenied.xhtml</form-error-page>
        </form-login-config>
    </login-config>

To describe the behavior using the log printed:
Load the page -> into the log "constructor", "init" (as expected)
Click Edit -> into the log "edit pushed, editing value was false" (as expected)
Click Edit Again -> into the log "constructor", "init" (expected "edit pushed, editing value was true")
From this point on, the listener is never called again, until you reload the page into the browser

Do you have any clue where to investigate?

thank you


UPDATE 2 The application is build with primefaces 3.5


UPDATE 3

we use JSF 2.2

We tested it on a glassfish3.1.2 environment and on a Payara5 too

0

There are 0 answers