I am using Mojarra 2.2.11
Starting from How to ajax-refresh dynamic include content by navigation menu? with one leftMenu part (in one xhtml) and one content part where another xhtml #{pageBean.page}
is included on the page: I want to update the content part where a list of Tabs are displayed versus the product selected in a selectOneMenu in the leftMenu part.
With the help of How to include another XHTML in XHTML using JSF 2.0 Facelets? I used ui:param
(Not sure if appropriate).
How can I use ui:param
to pass the newly selected product stored in the sessionProduct(String) parameter before the Tabs in the content part is refreshed according to the product?
(List of Tabs can be different depending on the product)
content.xhtml:
<ui:composition>
<h:outputScript name="js/fixviewstate.js" />
<div class="container-fluid">
<div class="row">
<div class="col-sm-3 col-md-2 sidebar">
<ui:include src="leftMenu.xhtml" />
</div>
<div id="target" class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
<ui:insert name="content" />
<ui:include src="/WEB-INF/includes/#{pageBean.page}.xhtml" >
<ui:param name="??" value="#{bean.product}" />
</ui:include>
</div>
</div>
</div>
</ui:composition>
leftMenu.xhtml:
<ui:composition>
<h:form>
<p:outputPanel style="float:center;margin-left: 33px">
<h:selectOneMenu value="#{bean.product}" onchange="submit();"
valueChangeListener="#{bean.init}">
<f:selectItems value="#{bean.products}" />
</h:selectOneMenu>
</p:outputPanel>
<h:form>
</ui:composition>
bean:
@ManagedBean
@ViewScoped
public class Bean implements Serializable{
@EJB
private PublicService publicService;
private List<Tab> tabs;
private List<Product> products;
private Product product;
ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
Map<String, Object> sessionMap = externalContext.getSessionMap();
@PostConstruct
public void init(ValueChangeEvent event) {
String newValue = (String) event.getNewValue();
sessionMap.remove("sessionProduct");
sessionMap.put("sessionProduct", (String) event.getNewValue());
this.product = publicService.getSpecificProduct((String) event.getNewValue()); // returns Product Object
this.tabs = publicService.getAllTabs(); // returns List<Tab> to be displayed in pageBean.page
}
Thank you for your time.