1

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.

Community
  • 1
  • 1
LEK
  • 83
  • 2
  • 11
  • Are you just trying to implement a product selection->product detail view navigation? Do you really need `#{pageBean.page}` to be dynamic,why not just a concrete view? `ui:param` is meant to be used only as a kind of variable for the xhtml views,not something you can pass as a param instead. What you should replace with IMO would be with a `f:param` in the `selectOneMenu`, so you might pass the product id in the url and display the product detail. Have a look at [this](http://stackoverflow.com/a/15438993/1199132) for how to pass params and have a look at the templating part of your given link. – Aritz Dec 27 '15 at 16:32
  • @XtremeBiker: I've several `h:commandlink`s below the selectOneMenu which setPage to the pageBean:, I should keep it. In the link: Is the "Source page" "block" the templating part? The `f:param` in selectOneMenu makes sense. What does IMO mean? – LEK Dec 27 '15 at 17:08
  • What I mean is you could perform the navigation from the selection menu as a GET request as well, instead of a POST one. I personally don't like the approach of using ajax for navigation (so JSF 1.x-ish), I prefer doing it with redirections, so browser url is changed and user can manage his own bookmarks. Also, views are loosely coupled this way, while if using ajax everything could end up in a big mess (as the view bean keeps being the same for all the views). That's something I would bother for if I were you and were building this application from scratch. – Aritz Dec 27 '15 at 21:49
  • @XtremeBiker: Thanks. Should I get rid of the `ui:include`? What would be your kick-off for a scratch in this context? – LEK Dec 27 '15 at 22:00

0 Answers0