includeViewParams=true 在模板化页面中不起作用
考虑这个模板:
<!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>
使用它的页面(/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:
@Named
@RequestScoped
public class PageBean implements Serializable
{
public String getFoo()
{
return foo;
}
public void setFoo(String foo)
{
this.foo = foo;
}
private String foo;
}
和这个 bean:
@Named
@ApplicationScoped
public class Util implements Serializable
{
public String currentPageAction()
{
return FacesContext.getCurrentInstance().getViewRoot().getViewId() +
"?faces-redirect=true&includeViewParams=true";
}
}
当我加载 http://localhost:8080/faces/pages/test.xhtml?foo=在浏览器中的栏
并单击
,URL更改为http://localhost:8080/faces/pages/test.xhtml
。也就是说,视图参数不包含在重定向 URL 中。
但是,当我重构页面以使其不使用模板时,它的行为符合预期。也就是说,视图参数包含在重定向 URL 中。
据我所知,
在放置在 Facelets 模板中时不会也不应该起作用。这不是这里发生的事情,所以这是一个不同的问题。规范中没有任何内容表明这是不能完成的。事实上,(据我所知)没有其他方法可以创建带有视图参数的基于模板的页面。
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>
the page's 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.
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.
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
之后注入
我有一个类似的问题,我将其解决为定义“元数据”集元数据在 f:view template.xhtml
I have a similar issue,i resolve it as define "metadata" set Metadata gets injected right after f:view
template.xhtml