Search code examples
javajsfjsf-2primefacesmanaged-bean

P:diallog is not synchronise with the values of My bean


I'm stuck here since yesterday I have a page jsf into p:dialog this is the dialog in page A

  <p:commandButton value="Ajouter"  rendered="#{LigneXL.resultat eq 'N existe pas'}"  oncomplete="Ajouter.show()" action="#{composantbean.initialise()}" >            
                </p:commandButton>

        <p:dialog id="Ajout" dynamic="true"  appendToBody="true" modal="true"  
            widgetVar="Ajouter" closable="true" height="800" width="800"  >
                  <ui:include src="/pagess/pagesComposant/AjoutCFromXls.xhtml" />
            </p:dialog>

this is the core of the display page into dialog

<ui:component 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:c="http://java.sun.com/jsp/jstl/core"
    xmlns:p="http://primefaces.org/ui">


<h:form id="form">  

      <h:panelGrid   columns="1" cellpadding="5" width="100%">  

        <p:panel header ="caracteristique composant" id="panel1" >
            <p:messages id="messages2" />

            <h:panelGrid   columns="4" cellpadding="5" width="100%">
            <h:outputLabel value="Ref_composant:" for="nom"  />  
            <p:inputText id="nom" value="#{composantbean.selcetitem.refComposant}"  required="true">
            <p:ajax event="keyup" listener="#{composantbean.filterListener}" />
            </p:inputText>      
            <h:outputLabel value="Fabricant:"   />  
            <p:selectOneMenu  value="#{composantbean.selectedFabricantId}" required="true">  
                <f:selectItem itemLabel="Select Fabricant" itemValue="" />  
                <f:selectItems value="#{composantbean.listfab}" var="fabri" itemValue="#{fabri.idFabricant}" itemLabel="#{fabri.nomFabricant}" />
                <p:ajax  event="change" listener="#{composantbean.fabListener()}"/>
            </p:selectOneMenu>  

            <h:outputLabel value="type_article :" />  
            <p:selectOneMenu  value="#{composantbean.selcetitem.typeArticle}" required="true">  
                <f:selectItem itemLabel="Select Type" itemValue="" />  
                <f:selectItem  itemLabel="Composant" itemValue="Composant" />
                <f:selectItem  itemLabel="Serie" itemValue="Serie" /> 
            </p:selectOneMenu>  

            <h:outputLabel value="Categorie :"  />  
            <p:selectOneMenu  value="#{composantbean.selectedCategoryId}" required="true" >  
                <f:selectItem itemLabel="Select categorie" itemValue="" />  
                <f:selectItems  value="#{composantbean.listcat}" var="cat" itemValue="#{cat.nomCat}" itemLabel="#{cat.nomCat}" /> 
                <p:ajax update="panlecart2"  event="change" listener="#{composantbean.catListener()}"/>
            </p:selectOneMenu>                          

            <h:outputLabel value="Type_famille :" />  
            <p:selectOneMenu  value="#{composantbean.selcetitem.typeFamille}" required="true">  
                <f:selectItem itemLabel="Select TypeFamille" itemValue="" />  
                <f:selectItem  itemLabel="Actif" itemValue="Actif" />
                <f:selectItem  itemLabel="Passifs" itemValue="Passifs" />
                <f:selectItem  itemLabel="Particuliers" itemValue="Particuliers" /> 
            </p:selectOneMenu>  

            <h:outputLabel value="Statut:"  /> 
            <p:selectOneMenu  value="#{composantbean.selcetitem.statut}" required="true">  
                <f:selectItem  itemLabel="Select Statut" itemValue="" />  
                <f:selectItem  itemLabel="Actif" itemValue="Actif" />
                <f:selectItem  itemLabel="Obsolete" itemValue="Obsolete" />
                <f:selectItem  itemLabel="En voi d obsolescence" itemValue="En voi d obsolescence" />
                <f:selectItem  itemLabel="Obsolete mais diponible" itemValue="Obsolete mais diponible" />
            </p:selectOneMenu>  

            <h:outputLabel value="Serie" />  
            <p:selectOneMenu  value="#{composantbean.selcetitem.serie}" >  
                <f:selectItem itemLabel="Select Serie" itemValue="" />  
                <f:selectItems value="#{composantbean.listSeries}" />  
            </p:selectOneMenu>                          

            <h:outputLabel value="RoHS :"  />  
            <p:selectOneMenu  value="#{composantbean.selcetitem.rohs}" required="true">  
                <f:selectItem  itemLabel="Select RoHS" itemValue="" />  
                <f:selectItem  itemLabel="NA" itemValue="NA" />
                <f:selectItem  itemLabel="OUI" itemValue="OUI" />
                <f:selectItem  itemLabel="NON" itemValue="NON" />
                <f:selectItem  itemLabel="Sans Statut" itemValue="Sans Statut" />
            </p:selectOneMenu>  

            <h:outputLabel value="SVHC_Presence"   />  
            <p:selectOneMenu  value="#{composantbean.selcetitem.svhcPresence}" required="true">  
                <f:selectItem  itemLabel="Select svhcPresence" itemValue="" />  
                <f:selectItem  itemLabel="NA" itemValue="NA" />
                <f:selectItem  itemLabel="OUI" itemValue="OUI" />
                <f:selectItem  itemLabel="NON" itemValue="NON" />
                <f:selectItem  itemLabel="Sans Statut" itemValue="Sans Statut" />
            </p:selectOneMenu>  

            <h:outputLabel value="SVHC_Source"   />  
            <p:selectOneMenu  value="#{composantbean.selcetitem.svhcSource}" >  
                <f:selectItem  itemLabel="Select svhcSource" itemValue="" />  
                <f:selectItem  itemLabel="Template" itemValue="Template" />
                <f:selectItem  itemLabel="FMD" itemValue="FMD" />
                <f:selectItem  itemLabel="COFC" itemValue="COFC" />
            </p:selectOneMenu>  

            <h:outputLabel value="Pdsl_Presence"   />  
            <p:selectOneMenu  value="#{composantbean.selcetitem.pdslPresence}" required="true">  
                <f:selectItem  itemLabel="Select pdslPresence" itemValue="" />  
                <f:selectItem  itemLabel="NA" itemValue="NA" />
                <f:selectItem  itemLabel="OUI" itemValue="OUI" />
                <f:selectItem  itemLabel="NON" itemValue="NON" />
                <f:selectItem  itemLabel="Sans Statut" itemValue="Sans Statut" />
            </p:selectOneMenu>  

            <h:outputLabel value="Suivi :"  />              
            <p:selectOneMenu  value="#{composantbean.selcetitem.suivi}" required="true">  
                <f:selectItem  itemLabel="Select suivi" itemValue="" />               
                <f:selectItem  itemLabel="OUI" itemValue="OUI" />
                <f:selectItem  itemLabel="NON" itemValue="NON" />
            </p:selectOneMenu>  


           </h:panelGrid>
          </p:panel>                                            
    <p:commandButton id="showDialogButton"   value="Ajouter" onclick="confirmation.show()" update="panel1" /> 
    <p:commandButton value="Annuler"  process="@this" onclick="Ajouter.hide()"> 

    </p:commandButton>

    <p:confirmDialog id="confirmDialog"   appendToBody="true"
            message="Confirmation d'Ajout "    header="Ajouter Composant" severity="alert" widgetVar="confirmation">  

        <p:commandButton id="confirm" value="Oui Sure"  oncomplete="confirmation.hide()"  process="@this"
                    action="#{composantbean.inserer2()}" > 
        <p:resetInput target="panel1" />  
        </p:commandButton> 
        <p:commandButton id="decline" value="Non encore" onclick="confirmation.hide()" type="button" />   

    </p:confirmDialog>  

</h:form> 
</ui:component>

the dialog sohw me form for adding a component .and it works fine

But the problem is that .when I call another time the dialog it keeps the previous values ​​of the inserted element

sow I make this methode bean composantbean

public void initialise(){
    selcetitem=new Composant();
    selcetitem.setRohs("NA");
    selcetitem.setSvhcPresence("NA");   
    selcetitem.setSvhcSource("");   
    selcetitem.setPdslPresence("NA");
    selcetitem.setSuivi("OUI");
    selcetitem.setTypeArticle("");
    selcetitem.setTypeFamille("");
    selcetitem.setStatut("");
    selectedFabricantId=0;
    selectedCategoryId="Selec";
}

this mlethode is executed but is never synchronise the dialog !!!

Haw soud I do !!!thank you in advance

note :the problem is solved when the page is out of the dialog .I think there is something rong in p:dialog is not refreching with my bean


Solution

  • Try to update the dialog after all methods are executed. You can do this by setting the update attribute in the commandButton:

     <p:commandButton value="Ajouter" rendered="#{LigneXL.resultat eq 'N existe pas'}"
           oncomplete="Ajouter.show()" action="#{composantbean.initialise()}" update="Ajout"/>