Losing ViewScoped bean when opening Dialog Framework

UI Components for JSF
Post Reply
YannickB
Posts: 13
Joined: 15 Aug 2013, 19:37
Location: Montreal, Canada

29 May 2014, 21:48

Hi there,

I have a page where I have a button, when I click on that button, a Dialog opens, but when I do, I lose the scope of my first backing bean.
I am looking at this blog post http://blog.primefaces.org/?p=2689, where Optimus says it's not supposed to happen and I'm wondering what I'm doing wrong :S

tableauDeBord.xhtml

Code: Select all

                     <p:commandButton
                        id="cb_menuCommande"
                        actionListener="#{tableauBordJSFCtrl.executeMenuCommande()}"
                        partialSubmit="true"
                        process="@this, som_menuCommande">
                      </p:commandButton>

TableauBordCtrl.java This bean holds commandeCourante and colisCourant variables

Code: Select all


@Named("tableauBordCtrl")
@ViewScoped
@Stateful
@StatefulTimeout(value = Constantes.SFSB_TIMEOUT_MINS)
public class TableauBordCtrl extends AbstractCtrl { // AbstractCtrl gives me EntityManager, Logger, etc.
   private CommandeDisplay       commandeCourante; //+getter/setter

   private ColisDisplay          colisCourant; //+getter/setter

}

TableauBordJSFCtrl.java (The view controller)

Code: Select all

@Named("tableauBordJSFCtrl")
@ViewScoped
public class TableauBordJSFCtrl implements Serializable {

   private static final long         serialVersionUID = 1L;

   @Inject
   private TableauBordCtrl           tableauBordCtrl; 

  public void executeMenuCommande() {

               // Paramètres extra
               Map<String, List<String>> params = new HashMap<String, List<String>>();
                
                ....defining params.....

               RequestContext.getCurrentInstance().openDialog("dialogNote.xhtml", getOptionsDialogNote(), params);

  }

   public void enregistrerDonneesNote() {

      String contexte = facesContext.getExternalContext().getRequestParameterMap().get("menuSource");
      MenuAction callerMenu = MenuAction.valueOf(contexte);

      // TODO YB: remplacer usager
      String usager = "usagerEnregistreDonnesNote";

      switch (callerMenu) {

         case SIGNALER_CROISAGE_COMMANDE:
            CommandeDisplay cd = tableauBordCtrl.getCommandeCourante();
            Commande c = cd.getCommande(); // [b]Fails here since getCommandeCourante() returns null since the bean has been lost[/b]
            actionWebManager.signalerCommandeNonRemiseCroisee(usager,
                                                              tableauBordCtrl.getCommandeCourante().getCommande(),
                                                              this.commentaireNote);
            break;
         default:
            log.error("callerMenu: {}", callerMenu);
      }

      this.codeRaisonNote = null;
      this.commentaireNote = null;

      RequestContext.getCurrentInstance().closeDialog(this.commentaireNote);

      majMenusCommandeEtForm();

   }


dialogNote.xhtml

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:f="http://java.sun.com/jsf/core"
   xmlns:h="http://java.sun.com/jsf/html"
   xmlns:p="http://primefaces.org/ui">

<h:head>
   <title>Saisi d'une note</title>
   <meta
      http-equiv="content-type"
      content="text/html; charset=UTF-8" />
   <meta
      http-equiv="X-UA-Compatible"
      content="IE=EDGE" />
   <h:outputStylesheet
      library="defaut"
      name="/css/style.css" />
</h:head>

<h:body>

   <h:form>

      <p:selectOneMenu
         id="note_som_codeRaison"
         value="#{tableauBordJSFCtrl.codeRaisonNote}"
         rendered="#{param.codeRaisonRequis == 'true'}">
         <f:selectItem
            noSelectionOption="true"
            itemLabel="#{msg['ga.codeRaison.noSelection']}"
            itemValue="#{null}" />
         <f:selectItems
            value="#{codesRaisonNoteEntreeManuelle}"
            var="codeRaison"
            itemValue="#{codeRaison}"
            itemLabel="#{codeRaison.description}" />
      </p:selectOneMenu>

      <div class="clear"></div>

      <p:inputTextarea
         id="note_ita_commentaireNote"
         value="#{tableauBordJSFCtrl.commentaireNote}"
         rows="20"
         autoResize="false"
         placeholder="#{msg['ga.watermark.commentaire']}"
         style="width: 100%;" />

      <div class="sectionBoutons">
         <p:commandButton
            id="note_cb_enregistrer"
            value="#{msg['ga.bouton.enregistrer']}"
            actionListener="#{tableauBordJSFCtrl.enregistrerDonneesNote}"
            icon="ui-icon-disk">

            <f:param name="menuSource" value="#{param.menuSource}" />

         </p:commandButton>


      </div>

   </h:form>
</h:body>

</html>


faces-config.xml

Code: Select all


<?xml version="1.0" encoding="UTF-8"?>

<faces-config
    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-facesconfig_2_0.xsd"
    version="2.0">

   <application>
      
      
      <!-- Dialogs -->
      <action-listener>
         org.primefaces.application.DialogActionListener
      </action-listener>
      <navigation-handler>
         org.primefaces.application.DialogNavigationHandler
      </navigation-handler>
      <view-handler>
         org.primefaces.application.DialogViewHandler
      </view-handler>
      
   </application>
       
</faces-config>



Thanks in advance for your support!
Primefaces 5.1, MyFaces, IBM WebSphere 8.5.5.3

YannickB
Posts: 13
Joined: 15 Aug 2013, 19:37
Location: Montreal, Canada

29 May 2014, 22:29

I added a log in the @PostConstruct of the TableauBordJSFCtrl and when I click the button that opens the dialog, the TableauBordJSFCtrl is re-instantiated (aka it goes in the @PostConstruct again) so I lose my link to TableauBordJSFCtrl.

I tried changing the button that opens the dialog from actionListener"" to action="" but I have the same behavior. Could it be the partialSubmit...

Still investigating!
Primefaces 5.1, MyFaces, IBM WebSphere 8.5.5.3

giovanefreitas
Posts: 1
Joined: 28 Jun 2012, 02:16

21 Aug 2014, 22:26

Any solution? I have the same problem.

tandraschko
PrimeFaces Core Developer
Posts: 3979
Joined: 03 Dec 2010, 14:11
Location: Bavaria, DE
Contact:

22 Aug 2014, 09:29

discussed multiple times... Dialog Framework openens the new view in a iframe, therefore the ViewScoped beans are lost.
Try to use something like ViewAccessScoped from DeltaSpike.
Last edited by tandraschko on 14 Sep 2014, 03:19, edited 2 times in total.
Thomas Andraschko

PrimeFaces | PrimeFaces Extensions

Apache Member | OpenWebBeans, DeltaSpike, MyFaces, BVal, TomEE

Sponsor me: https://github.com/sponsors/tandraschko
Blog: http://tandraschko.blogspot.de/
Twitter: https://twitter.com/TAndraschko

gustavomr
Posts: 2
Joined: 09 Jul 2014, 19:08

31 Aug 2014, 17:34

Hi,

Having same problem. Any solution to this?

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 39 guests