IncludeViewParams = true does not work on template pages

Consider this template:

<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:ui="http://java.sun.com/jsf/facelets"> <f:view contentType="text/html"> <ui:insert name="metadata"/> <h:head> <title></title> </h:head> <h:body> <ui:insert name="content"/> </h:body> </f:view> </html> 

this page that uses it (/pages/test.xhtml):

 <html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:ui="http://java.sun.com/jsf/facelets"> <f:view contentType="text/html"> <h:head> <title></title> </h:head> <h:body> <ui:composition template="/WEB-INF/templates/testLayout.xhtml"> <ui:define name="metadata"> <f:metadata> <f:viewParam name="foobar" value="#{pageBean.foo}"/> </f:metadata> </ui:define> <ui:define name="content"> <h:form> <h:commandLink value="Click" action="#{util.currentPageAction()}"/> </h:form> </ui:define> </ui:composition> </h:body> </f:view> </html> 

bean page:

 @Named @RequestScoped public class PageBean implements Serializable { public String getFoo() { return foo; } public void setFoo(String foo) { this.foo = foo; } private String foo; } 

and bean:

 @Named @ApplicationScoped public class Util implements Serializable { public String currentPageAction() { return FacesContext.getCurrentInstance().getViewRoot().getViewId() + "?faces-redirect=true&includeViewParams=true"; } } 

When I download http://localhost:8080/faces/pages/test.xhtml?foo=bar in the browser and press <h:commandLink/> , the URL changes to http://localhost:8080/faces/pages/test.xhtml . That is, the view options are not included in the redirect URL.

However, when I reorganize the page so that it does not use a template, it behaves as expected. That is, presentation parameters are included in the redirect URL.

I understand that <f:metadata/> does not work and should not work when placed inside the facelets template. This is not what is happening here, so this is another problem. There is nothing in the specification to say that this is impossible. Indeed, there would be no other way (as far as I know) to create a page based on a template with presentation parameters.

+4
source share
1 answer

I have a similar problem, I solve it as the definition of "metadata". Metadata is entered immediately after f: view

 <ui:define name="metadata"> <f:metadata> <f:viewParam name="id" .../> </f:metadata> </ui:define> 

template.xhtml

  <html xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://java.sun.com/jsf/core" xml:lang="en" lang="en"> <f:view> <ui:insert name="metadata"/> <div id="container"> <ui:insert name="content"/> </div> </f:view> 
0
source

Source: https://habr.com/ru/post/1393993/


All Articles