【发布时间】:2012-02-23 06:07:38
【问题描述】:
考虑这个模板:
<!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;
}
还有这个豆子:
@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=bar 并单击<h:commandLink/> 时,URL 更改为http://localhost:8080/faces/pages/test.xhtml。也就是说,视图参数不包含在重定向 URL 中。
但是,当我重构页面使其不使用模板时,它的行为符合预期。也就是说,视图参数包含在重定向 URL 中。
我了解<f:metadata/> 在放置在 facelets 模板中时不会也不应该工作。这不是这里发生的事情,所以这是一个不同的问题。规范中没有任何内容可以说这是无法做到的。确实,没有其他方法(据我所知)来创建带有视图参数的基于模板的页面。
【问题讨论】:
-
对this bug添加了评论。
-
我希望有一天能解决这个问题。我投了赞成票。
-
我有一个与
<h:button />或<h:link />类似的问题,其中包含includeViewParams="true"属性不会产生与使用<f:param />条目重复视图参数相同的行为。当使用includeViewParams时,链接/GET 请求中的参数值来自outcome页面的支持bean,而不是来自提供给当前页面的视图参数,我认为它们应该是。 Core JavaServer Faces - Third Edition 页。 91 意味着这两种方法应该可以互换。
标签: java jsf-2 facelets post-redirect-get