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