I use h:link with includeViewParams=true to navigate between my list and view pages and make the view page URLs bookmarkable but it doesn't work. Below is related portion of my code:
in layout.xhtml (my template):
<f:view locale="#{localeBean.lang}"> <ui:insert name="metadata"/> in Articles.xhtml (my list page):
<h:form> <p:datagrid var="item" value="articleController.items"> <p:column> <h:link outcome="View_Articles?faces-redirect=true&includeViewParams=true" styleClass="view-details"> <h:outputText value="#{item.title}"/> <f:param name="id" value="#{item.articleId}"/> </h:link> </p:column> </p:datagrid> </h:form> in View_Article.xhtml (my view details page):
<ui:composition template="./WEB-INF/templates/layout.xhtml"> <ui:define name="metadata"> <f:metadata> <f:viewParam name="id" value="#{articleController.id}" /> <f:viewParam name="id" value="#{articleLclController.id}"/> </f:metadata> </ui:define> Further information: I use JSF 2.2, ocpsoft rewrite filter, primefaces library, and ArticleController.java is session scoped.
I have tried the following:
1- I used h:commandLink; with this, the navigation worked but the URL didn't include view-params
Articles.xhtml:
<h:commandLink id="viewArticleDetails" action="#{articleController.viewArticleByID()}" styleClass="view-details"> <h:outputText value="View Details"/> <f:setPropertyActionListener target="#{articleController.id}" value="#{item.articleId}"/> <f:setPropertyActionListener target="#{articleLclController.id}" value="#{item.articleId}"/> </h:commandLink> ArticleController.java: ...
private Long id; public Long getId() { return id; } public void setId(Long id) { this.id = id; current = ejbFacade.find(id); } public String viewArticleByID(){ return "View_Article?faces-redirect=true&includeViewParams=true"; } ... I expected the URL to be http://localhost:8080/testApp/en/View_Article?id=1 but it was like `http://localhost:8080/testApp/en/View_Article
2- I inserted http://localhost:8080/testApp/en/View_Article?id=1 and it worked in both cases.