0

excuse me to borther once more actually I've been through an issue for a long while I tried to flick through variours post on various forum without finding a solution. I developped a web application with Hibernate, Spring and PrimeFaces; everything was fine until I decided to deploy on another tomcat different from the one used by netbeans. when I deploy it on the other Tomcat, the project works well for everything related to @RequestScoped bean but for @ViewScoped bean it is not the case, @ViewScoped bean seems to die as soon as it is created

here is one of my bean

package com.dresen.dresen.Beans;

import com.dresen.dresen.ServiceInterface.ICadreService;
import com.dresen.dresen.ServiceInterface.ICorpsService;
import com.dresen.dresen.ServiceInterface.IGradeFonctioService;
import com.dresen.dresen.entities.Cadre;
import com.dresen.dresen.entities.Categorie;
import com.dresen.dresen.entities.Corps;
import com.dresen.dresen.entities.GradeFonctio;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;

/**
 *
 * @author Vivien Saa
 */
@ManagedBean
@ViewScoped
public class GradeFonctioBean {

    @ManagedProperty(value = "#{IGradeFonctioService}")
    private IGradeFonctioService IGradeFonctioService;

    @ManagedProperty(value = "#{ICadreService}")
    private ICadreService iCadreService;

    @ManagedProperty(value = "#{ICorpsService}")
    private ICorpsService iCorpsService;

    private List<Corps> listCorps;
    private List<Cadre> listCadre;
    private List<Cadre> listAge;
    private long idCadre;
    private long idCorps;
    private GradeFonctio gradeFonctio = new GradeFonctio();
    private Cadre cadre = new Cadre();

    public GradeFonctioBean() {
        idCadre = 0L;
        idCorps = 0L;
    }

    public IGradeFonctioService getIGradeFonctioService() {
        return IGradeFonctioService;
    }

    public void setIGradeFonctioService(IGradeFonctioService IGradeFonctioService) {
        this.IGradeFonctioService = IGradeFonctioService;
    }

    public ICadreService getiCadreService() {
        return iCadreService;
    }

    public void setiCadreService(ICadreService iCadreService) {
        this.iCadreService = iCadreService;
    }

    public List<Cadre> getListCadre() {
        return iCadreService.findCadreByIdCorps(idCorps);
    }

    public void setListCadre(List<Cadre> listCadre) {
        this.listCadre = listCadre;
    }

    public long getIdCadre() {
        return idCadre;
    }

    public void setIdCadre(long idCadre) {
        this.idCadre = idCadre;
    }

    public GradeFonctio getGradeFonctio() {
        return gradeFonctio;
    }

    public void setGradeFonctio(GradeFonctio gradeFonctio) {
        this.gradeFonctio = gradeFonctio;
    }

    public ICorpsService getiCorpsService() {
        return iCorpsService;
    }

    public List<Corps> getListCorps() {
        return iCorpsService.findAllCorps();
    }

    public void setListCorps(List<Corps> listCorps) {
        this.listCorps = listCorps;
    }

    public void setiCorpsService(ICorpsService iCorpsService) {
        this.iCorpsService = iCorpsService;
    }

    public Cadre getCadre() {
        return cadre;
    }

    public void setCadre(Cadre cadre) {
        this.cadre = cadre;
    }

    public long getIdCorps() {
        return idCorps;
    }

    public void setIdCorps(long idCorps) {
        this.idCorps = idCorps;
    }

    public List ages() {
        List listAges = new ArrayList();
        listAges.add(45);
        listAges.add(50);
        listAges.add(55);
        listAges.add(60);
        listAges.add(65);
        return listAges;
    }

    public List<Categorie> categories() {
        List<Categorie> listCategorie = new ArrayList<Categorie>();
        listCategorie.addAll(Arrays.asList(Categorie.values()));
        return listCategorie;
    }

    /*
    this is to reinitialize/reinitialize the entity gradeFonctio before creating another
     */
    public void initGradeFonc() {
        idCorps = 0L;
        cadre = null;
        gradeFonctio = new GradeFonctio();
    }

    /*
    this is aim to initialize the oneMenu to nothing before updating
     */
    public void updateGradeFonc() {
        if (gradeFonctio == null) {
            idCorps = 0L;
            cadre = null;
        } else {
            cadre = gradeFonctio.getCadre();
            idCorps = cadre.getCorps().getId();
        }
    }

    public GradeFonctio createGradeFonction() throws Exception {
        try {
            cadre = iCadreService.findCadreById(idCadre);
            gradeFonctio.setCadre(cadre);
            IGradeFonctioService.createGradeFonctio(gradeFonctio);
            FacesMessage msg = new FacesMessage("Grade enregistré avec succès!");
            FacesContext.getCurrentInstance().addMessage(null, msg);
            return gradeFonctio;
        } catch (Exception e) {
            FacesMessage msg = new FacesMessage("Echec de l'enregistrement du grade, vérifier les informations!");
            FacesContext.getCurrentInstance().addMessage(null, msg);
            throw e;
        }
    }

    public GradeFonctio findGradeFonctionById() {
        return IGradeFonctioService.findGradeFonctioById(gradeFonctio.getId());
    }

    public GradeFonctio updateGradeFonction() throws Exception {
        try {
            cadre = iCadreService.findCadreById(idCadre);
            gradeFonctio.setCadre(cadre);
            IGradeFonctioService.updateGradeFonctio(gradeFonctio);
            FacesMessage msg = new FacesMessage("Grade modifié avec succès!");
            FacesContext.getCurrentInstance().addMessage(null, msg);
            return gradeFonctio;
        } catch (Exception e) {
            FacesMessage msg = new FacesMessage("Echec de la modification du grade, vérifier les informations!");
            FacesContext.getCurrentInstance().addMessage(null, msg);
            throw e;
        }
    }

    public List<GradeFonctio> findAllGradeFonction() {
        return IGradeFonctioService.findAllGradeFonctio();
    }
}
<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
         version="3.0">
    <display-name>personnel MINESEC</display-name>
    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>/faces/*</url-pattern>
        <url-pattern>*.xhtml</url-pattern>
    </servlet-mapping>
    <session-config>
        <session-timeout>30</session-timeout>
    </session-config>
    <welcome-file-list>        
        <welcome-file>
            faces/Menu.xhtml
        </welcome-file>
    </welcome-file-list>
    <listener>        
        <listener-class> org.springframework.web.context.request.RequestContextListener </listener-class>    
    </listener>    
    <listener>        
        <listener-class> org.springframework.web.context.ContextLoaderListener </listener-class>    
    </listener>   
    <context-param>        
        <param-name>contextConfigLocation</param-name>       
        <param-value>/WEB-INF/Spring-Config.xml</param-value>    
    </context-param>

    <context-param>
        <param-name>javax.faces.PROJECT_STAGE</param-name>
        <param-value>Development</param-value>
    </context-param>
   
    <context-param>
        <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
        <param-value>client</param-value>
    </context-param>
   
    <context-param>
        <param-name>javax.faces.PARTIAL_STATE_SAVING</param-name>
        <param-value>false</param-value>
    </context-param>
   
    <context-param>
        <param-name>javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL</param-name>
        <param-value>true</param-value>
    </context-param>
   
    <context-param>
        <param-name>javax.faces.DATETIMECONVERTER_DEFAULT_TIMEZONE_IS_SYSTEM_TIMEZONE</param-name>
        <param-value>true</param-value>
    </context-param>
    
    
    <filter>
        <filter-name>PrimeFaces FileUpload Filter</filter-name>
        <filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
        <init-param>
            <param-name>thresholdSize</param-name>
            <param-value>10240</param-value> <!-- 10 Mb -->
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>PrimeFaces FileUpload Filter</filter-name>
        <servlet-name>Faces Servlet</servlet-name>
    </filter-mapping>
    
    <context-param>
        <param-name>primefaces.THEME</param-name>
        <param-value>redmond</param-value>
    </context-param>
    <context-param>
        <param-name>primefaces.UPLOADER</param-name>
        <param-value>auto</param-value>
    </context-param>

</web-app>
<?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:ui="http://xmlns.jcp.org/jsf/facelets"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:f="http://xmlns.jcp.org/jsf/core"
      xmlns:p="http://primefaces.org/ui">

    <ui:composition template="/TemplateMenu.xhtml">
        <ui:define name="body">
            <f:view>
                <p:dialog widgetVar="dlg" header=" Enregistrer une nouveau grade pour les fonctionnaires " hideEffect="explode" showEffect="explode" modal="true" appendTo="@(body)">
                    <h:form id="formAjouter" >
                        <h:panelGrid id="panelAjouter" columns="2">
                            <p:outputLabel value="Corps:" />       
                            <p:selectOneMenu id="corps" value="#{gradeFonctioBean.idCorps}"  label="corps"  filter="true" filterMatchMode="startsWith" panelStyle="width:220px" required="true">
                                <p:ajax  event="change" update="cadre" />
                                <f:selectItem itemLabel="Selectioner le corps" itemValue="" noSelectionOption="true"  />
                                <f:selectItems var="custe1" value="#{gradeFonctioBean.listCorps}"   itemLabel="#{custe1.intituleCorps}" itemValue="#{custe1.id}" itemLabelEscaped="true" />
                            </p:selectOneMenu>
                            <p:outputLabel value="Cadre:" />       
                            <p:selectOneMenu id="cadre" value="#{gradeFonctioBean.idCadre}" filter="true" filterMatchMode="startsWith" panelStyle="width:220px" required="true">
                                <f:selectItems var="custe2" value="#{gradeFonctioBean.listCadre}"   itemLabel="#{custe2.intituleCadre}" itemValue="#{custe2.id}" itemLabelEscaped="true" />
                            </p:selectOneMenu>
                            <p:outputLabel value="Intitule :" for="intitule" />
                            <p:inputText id="intitule" value="#{gradeFonctioBean.gradeFonctio.intituleGradeFonctio}" title="intitulé" required="true"/>
                            <p:outputLabel value="Code :" for="code" />
                            <p:inputText id="code" value="#{gradeFonctioBean.gradeFonctio.codeGradeFonctio}" title="Code" required="true"/>
                            <p:outputLabel value="Catégorie:" for="categorie" />
                            <p:selectOneMenu id="categorie" value="#{gradeFonctioBean.gradeFonctio.categororie}"  label="categorie"  filter="true" filterMatchMode="startsWith" panelStyle="width:220px" required="true">
                                <f:selectItem itemLabel="Selectioner la catégorie" itemValue="" noSelectionOption="true"  />
                                <f:selectItems var="custe1" value="#{gradeFonctioBean.categories()}" />
                            </p:selectOneMenu>                            
                            <p:outputLabel value="Age de départ à la retraite: " for="age"/>  
                            <p:selectOneMenu id="age" value="#{gradeFonctioBean.gradeFonctio.retraite}" effect="fold" editable="true" required="true">  
                                <f:selectItem itemLabel="Selectionner un age" itemValue="" />  
                                <f:selectItems var="age" value="#{gradeFonctioBean.ages()}" itemLabelEscaped="true"/> 
                            </p:selectOneMenu>  
                            <p:commandButton value="Enregistrer" action="#{gradeFonctioBean.createGradeFonction()}"  oncomplete="PF('dlg').hide()" update=":tableForm:table, messages" id="bout1" ajax="false" />
                        </h:panelGrid>
                        <p:growl id="messages" showDetail="true"/> 
                    </h:form>
                </p:dialog>
                <p:dialog widgetVar="dl" header=" Modifier une structure d'attache" hideEffect="fold" showEffect="explode" resizable="true" modal="true" appendTo="@(body)">
                    <h:form id="formModifier" enctype="multipart/form-data">                
                        <h:panelGrid id="panelGModifier" columns="2">
                            <p:outputLabel value="Corps:" />       
                            <p:selectOneMenu id="corps" value="#{gradeFonctioBean.idCorps}"  label="corps"  filter="true" filterMatchMode="startsWith" panelStyle="width:220px" required="true">
                                <p:ajax  event="change" update="cadre" />
                                <f:selectItem itemLabel="Selectioner le corps" itemValue="" noSelectionOption="true"  />
                                <f:selectItems var="custe1" value="#{gradeFonctioBean.listCorps}"   itemLabel="#{custe1.intituleCorps}" itemValue="#{custe1.id}" itemLabelEscaped="true" />
                            </p:selectOneMenu>
                            <p:outputLabel value="Cadre:" />       
                            <p:selectOneMenu id="cadre" value="#{gradeFonctioBean.idCadre}" filter="true" filterMatchMode="startsWith" panelStyle="width:220px" required="true">
                                <f:selectItems var="custe2" value="#{gradeFonctioBean.listCadre}"   itemLabel="#{custe2.intituleCadre}" itemValue="#{custe2.id}" itemLabelEscaped="true" />
                            </p:selectOneMenu>
                            <p:outputLabel value="Intitule :" for="intitule" />
                            <p:inputText id="intitule" value="#{gradeFonctioBean.gradeFonctio.intituleGradeFonctio}" title="intitulé" required="true"/>
                            <p:outputLabel value="Code :" for="code" />
                            <p:inputText id="code" value="#{gradeFonctioBean.gradeFonctio.codeGradeFonctio}" title="Code" required="true"/>
                            <p:outputLabel value="Catégorie:" for="categorie"/>
                            <p:selectOneMenu id="categorie" value="#{gradeFonctioBean.gradeFonctio.categororie}"  label="categorie"  filter="true" filterMatchMode="startsWith" panelStyle="width:220px" required="true">
                                <f:selectItem itemLabel="Selectioner la catégorie" itemValue="" noSelectionOption="true"  />
                                <f:selectItems var="custe1" value="#{gradeFonctioBean.categories()}" />
                            </p:selectOneMenu>  
                            <p:outputLabel value="Age de départ à la retraite: " for="age"/>  
                            <p:selectOneMenu id="age" value="#{gradeFonctioBean.gradeFonctio.retraite}" effect="fold" editable="true" required="true">  
                                <f:selectItem itemLabel="Selectionner un age" itemValue="" />  
                                <f:selectItems var="age" value="#{gradeFonctioBean.ages()}" itemLabelEscaped="true"/> 
                            </p:selectOneMenu>  
                            <h:inputHidden id="number" value="#{gradeFonctioBean.gradeFonctio.id}" />
                            <p:commandButton value="Modifier" action="#{gradeFonctioBean.updateGradeFonction()}"  oncomplete="PF('dl').hide()" update=":tableForm:table, messages" id="bout1" ajax="false" />
                        </h:panelGrid>
                        <p:growl id="messages" showDetail="true"/> 
                    </h:form>
                </p:dialog> 
            </f:view>


            <f:view>
                <h:form id='tableForm'>
                    <p:contextMenu for="table">  
                        <p:menuitem value="New" actionListener="#{gradeFonctioBean.initGradeFonc()}" update=":formAjouter:panelAjouter" oncomplete="PF('dlg').show()" /> 
                        <p:menuitem value="Update" actionListener="#{gradeFonctioBean.updateGradeFonc()}" update=":formModifier:panelGModifier" oncomplete="PF('dl').show()"/>  
                    </p:contextMenu>  

                    <p:dataTable value="#{gradeFonctioBean.findAllGradeFonction()}" var="item" paginator="true" rows="10" paginatorTemplate=" {CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown} " id="table" rowsPerPageTemplate="5,10,15" selectionMode="single" selection="#{gradeFonctioBean.gradeFonctio}" rowKey="#{item.id}">
                        <f:facet name="header">
                            La liste des grades de fonctionnaire
                        </f:facet>

                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="Intitulé du grade"/>
                            </f:facet> 
                            <h:outputText value="#{item.intituleGradeFonctio}"/>
                        </p:column>
                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="Code du grade"/>
                            </f:facet> 
                            <h:outputText value="#{item.codeGradeFonctio}"/>
                        </p:column>
                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="Catégorie correspondante"/>
                            </f:facet>
                            <h:outputText value="#{item.categororie}"/>
                        </p:column>

                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="Age de départ a la retraite"/>
                            </f:facet>
                            <h:outputText value="#{item.retraite}"/>
                        </p:column>
                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="Cadre du grade"/>
                            </f:facet>
                            <h:outputText value="#{item.cadre.intituleCadre}"/>
                        </p:column>

                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="corps"/>
                            </f:facet>
                            <h:outputText value="#{item.cadre.corps.intituleCorps}"/>
                        </p:column>

                    </p:dataTable>
                    <p:toolbar>
                        <f:facet name="left">
                            <p:commandButton type="push"  actionListener="#{gradeFonctioBean.initGradeFonc()}"  onclick="PF('dlg').show();" value="Nouvelle Structure" icon="ui-icon-disk" />                
                            <span class="ui-separator">
                                <span class="ui-icon ui-icon-grip-dotted-vertical" />
                            </span>
                            <p:commandButton type="push" title="Save" image="ui-icon-disk" />
                            <p:commandButton type="push" title="Update" icon="ui-icon-arrowrefresh-1-w"/>
                            <p:commandButton type="push" title="Print" image="ui-icon-print"/>
                        </f:facet>
                    </p:toolbar>
                </h:form>
            </f:view>
        </ui:define>
    </ui:composition>
</html>
Vivien SA'A
  • 727
  • 8
  • 16
  • What's the reason why you're setting the PARTIAL_STATE_SAVING to false? http://stackoverflow.com/a/10337452/1199132 – Aritz Jul 31 '16 at 18:42
  • [mcve] please... see also http://www.stackoverflow.com/tags/jsf/info. And post which post you tried and why they did not work. See [ask] for this – Kukeltje Jul 31 '16 at 20:21

0 Answers0