4
考虑此模板: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>
页的豆:
@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=bar
并单击<h:commandLink/>
时,URL更改为http://localhost:8080/faces/pages/test.xhtml
。也就是说,视图参数不包含在重定向网址中。
但是,当我重构页面,使其不使用模板时,它的行为如预期。也就是说,视图参数包含在重定向网址中。
据我所知,<f:metadata/>
没有,当放置在facelets模板中时不应该工作。这不是发生在这里的事情,所以这是一个不同的问题。规范中没有什么可以说这是不可能完成的。事实上,根据我的知识,没有其他方法可以创建一个带有视图参数的基于模板的页面。
添加注释[这个bug](http://java.net/jira/browse/JAVASERVERFACES-2260)。 – 2012-01-31 15:26:25
我希望这有一天得到修复。我投了赞成票。 – 2012-02-10 07:16:37
我对' '或' '有类似的问题,其中包括属性'includeViewParams =“true”'不会产生与使用' '条目重复视图参数相同的行为。当使用'includeViewParams'时,link/GET请求中的参数值来自'outcome'页面的支持bean,而不是来自提供给当前页面的视图参数,因为我相信它们应该是。 [核心JavaServer Faces - 第三版](http://horstmann.com/corejsf/)p。 91意味着这两种方法应该是可以互换的。 –
2012-06-12 19:31:08