Environment:
- Jboss 5.2
- Java 7
- JSF 2.1.2
- Primefaces 6.2
- Mojarra (1.2_13-b01-FCS)
I want to load a menu generated in @PostConstruct method in ViewScope bean but when the web page is loaded the menu is void.
The page persona.xhtml is loaded from a redirect from another web page and the PersonaBean has ViewScope. PersonaBean init() @PostConstruct is executed but no values are loaded in the web page.
The specific bean CustomMenuBean (view scope) is loaded but the CustomMenuBean.menu is null in web page but it has the menu in the bean (when I stop there in debug mode CustomMenuBean.menu is correctly loaded).
So I tried to update frmMenus with a button for testing purposes and it works well after web page refresh with following code.
<p:commandButton value="update" action="#{personaBean.doNothing}" process=":frmMenus" update=":frmMenus"/>
Web page persones.xhtml
...
<p:dataTable id="lstPersones" var="item" value="#{personesBean.items}"...>
<p:ajax event="rowSelect" listener="#{personesBean.onRowSelect}"/>
...
PersonesBean.java
@ViewScoped
@ManagedBean
public class PersonesBean ...
...
@Override
public void onRowSelect(SelectEvent event) {
...
HttpServletRequest origRequest = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
String ctxPath = origRequest.getContextPath();
FacesContext.getCurrentInstance().getExternalContext().redirect(ctxPath + "\gestio\persona.xhtml");
...
Web page persona.xhtml
...
<h:form id="frmMenus">
<div class="layout-menu-container #{usuariPreferenciesBean.menuClass}">
<div class="nano">
<div class="nano-content menu-scroll-content">
<ui:include src="menu_profile.xhtml"/>
<pu:menu id="mnu_custom" widgetVar="mnu_custom" model="#{customMenuBean.menu}"/>
<p:separator/>
</div>
</div>
</div>
</h:form>
<h:form id="frmPersona">
<!-- person data -->
</h:form>
...
PersonaBean.java
@ViewScoped
@ManagedBean
public class PersonaBean...
...
@ManagedProperty(value = "#{customMenuBean}")
private CustomMenuBean cstmMenuBean; //View scope Bean to store menu
@PostConstruct
public void init() {
super.init(Persona.class);
super.setService(service);
cstmMenuBean.generateMenu(); //create a DefaultMenuModel()
}
...
I don't know what I'm missing.