I have a list of commandLinks in a JSF page where each commandLink sets to the corresponding page in a content.xhtml page.
Problem: In the below list of commandLink
s only the last one works successfully:
<ui:composition>
<h:form>
<ul class="nav nav-sidebar">
<li>
<h:commandLink value="Title1" >
<f:param value="#{pageBean.setPage('title1')}" />
</h:commandLink>
</li>
<li>
<h:commandLink value="Title2" >
<f:param value="#{pageBean.setPage('title2')}" />
</h:commandLink>
</li>
<li>
<h:commandLink value="Title3" >
<f:param value="#{pageBean.setPage('title3')}" />
</h:commandLink>
</li>
</ul>
</h:form>
Per How can I pass selected row to commandLink inside dataTable? Item Number 2, I understand that there is a need of accessing the request parameter map. Is this correct in this case with <f:param>
? How can I set one page to be included below with the correct title page?
content.xhtml
<ui:composition>
<div class="container-fluid">
<div class="row">
<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:insert>
</div>
</div>
</div>
</ui:composition>
PageBean
@ManagedBean
@ViewScoped
public class PageBean implements Serializable {
private String page;
@PostConstruct
public void init() {
page = "title1"; // Default include.
}
//getter & setter
}
Related to the problem: when PageBean is RequestScoped events inside title1 work properly but the commandLinks fail. when PageBean is ViewScoped event in title1 don't work and I have only the last commandLink working.
What am I doing wrong? Thanks.
EDIT (per below mentioned tutorial):
<li>
<h:commandLink value="Title1" action="#{pageBean.setPage}" >
<f:param name="action" value="title1" />
</h:commandLink>
</li>
The below method is NOT called
public void setPage() {
Map<String, String> params = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
String page = params.get("action");
System.out.println("page " + page);
this.page = page;
}