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):
这个使用它的页面(/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>
the page's bean:
页面的bean:
@Named
@RequestScoped
public class PageBean implements Serializable
{
public String getFoo()
{
return foo;
}
public void setFoo(String foo)
{
this.foo = foo;
}
private String foo;
}
and this bean:
而这个豆子:
@Named
@ApplicationScoped
public class Util implements Serializable
{
public String currentPageAction()
{
return FacesContext.getCurrentInstance().getViewRoot().getViewId() +
"?faces-redirect=true&includeViewParams=true";
}
}
When I load http://localhost:8080/faces/pages/test.xhtml?foo=bar
in the browser and click the <h:commandLink/>
, the URL changes to http://localhost:8080/faces/pages/test.xhtml
. That is, the view parameters are not included in the redirect URL.
当我在浏览器中加载http:// localhost:8080 / faces / pages / test.xhtml?foo = bar并单击
However, when I refactor the page such that it doesn't use a template, it behaves as expected. That is, the view parameters are included in the redirect URL.
但是,当我重构页面使其不使用模板时,它的行为与预期的一样。也就是说,视图参数包含在重定向URL中。
I understand that <f:metadata/>
doesn't and isn't supposed to work when placed inside a facelets template. This is not what's happening here, so it's a different issue. There's nothing in the spec to say that this can't be done. Indeed, there would be no other way (to my knowledge) to create a template-based page with view parameters.
我知道
1 个解决方案
#1
0
I have a similar issue,i resolve it as define "metadata" set Metadata gets injected right after f:view
我有一个类似的问题,我解决它定义“元数据”集元数据在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>
#1
0
I have a similar issue,i resolve it as define "metadata" set Metadata gets injected right after f:view
我有一个类似的问题,我解决它定义“元数据”集元数据在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>