Note that there are some explanatory texts on larger screens.

plurals
  1. PO@ViewScoped bean recreated on every postback request when using JSF 2.2
    primarykey
    data
    text
    <p>I'm having an issue similar to <a href="https://stackoverflow.com/questions/14215098/view-scoped-bean-recreated-on-post-when-url-parameters-not-used">this post</a> and the answer from @BalusC with 3 solutions but:</p> <ul> <li>I'm not using of the mentioned EL expressions</li> <li>I don't want to go with the second solution (it's complex enough for me like this)</li> <li>and partial state saving is set to false.</li> </ul> <p>My code is as follows:</p> <p><code>index.xhtml</code>:</p> <pre><code>&lt;?xml version="1.0" encoding="windows-1256" ?&gt; &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:p="http://primefaces.org/ui" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:f="http://java.sun.com/jsf/core"&gt; &lt;h:head&gt; &lt;title&gt;Insert title here&lt;/title&gt; &lt;/h:head&gt; &lt;h:body&gt; &lt;h:form&gt; &lt;p:panelMenu id="westMenu"&gt; &lt;p:submenu id="sub1" label="System Monitor"&gt; &lt;p:menuitem id="menu1" value="live monitoring" action="#{menusBean.activateMenu('sub1_menu1')}" update=":centerPane,westMenu" disabled="#{menusBean.active['sub1_menu1']}" /&gt; &lt;p:menuitem id="menu2" value="reports" action="#{menusBean.activateMenu('sub1_menu2')}" update=":centerPane,westMenu" disabled="#{menusBean.active['sub1_menu2']}" /&gt; &lt;/p:submenu&gt; &lt;p:submenu id="sub2" label="Charging System Nodes" /&gt; &lt;p:submenu id="sub3" label="Additional Nodes" /&gt; &lt;/p:panelMenu&gt; &lt;/h:form&gt; &lt;h:panelGroup id="centerPane"&gt; ... &lt;/h:panelGroup&gt; &lt;/h:body&gt; &lt;/html&gt; </code></pre> <p><code>MenusBean.java</code>:</p> <pre><code>package menus; import java.io.Serializable; import java.util.HashMap; import java.util.Map; import javax.faces.bean.ManagedBean; import javax.faces.bean.SessionScoped; import javax.faces.view.ViewScoped; @ManagedBean @ViewScoped public class MenusBean implements Serializable{ private static final long serialVersionUID = -7793281454064343472L; private String mainPage="sub1_menu1"; private Map&lt;String, Boolean&gt; active; public MenusBean(){ System.out.println("MenusBean created"); active = new HashMap&lt;&gt;(); active.put(mainPage, true); active.put("sub1_menu2", false); } public boolean activateMenu(String page){ active.put(mainPage, false); active.put(page, true); mainPage = page; for (Map.Entry&lt;String, Boolean&gt; e : active.entrySet()) System.out.println(e.getKey()+":"+e.getValue()); return true; } public Map&lt;String, Boolean&gt; getActive() { return active; } } </code></pre> <p>When executed, I get:</p> <pre> MenusBean created MenusBean created MenusBean created </pre> <p>How is this caused and how can I solve it?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload