2012-01-31 21 views
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模板中时不应该工作。这不是发生在这里的事情,所以这是一个不同的问题。规范中没有什么可以说这是不可能完成的。事实上,根据我的知识,没有其他方法可以创建一个带有视图参数的基于模板的页面。

+0

添加注释[这个bug](http://java.net/jira/browse/JAVASERVERFACES-2260)。 – 2012-01-31 15:26:25

+0

我希望这有一天得到修复。我投了赞成票。 – 2012-02-10 07:16:37

+0

我对''或''有类似的问题,其中包括属性'includeViewParams =“true”'不会产生与使用''条目重复视图参数相同的行为。当使用'includeViewParams'时,link/GET请求中的参数值来自'outcome'页面的支持bean,而不是来自提供给当前页面的视图参数,因为我相信它们应该是。 [核心JavaServer Faces - 第三版](http://horstmann.com/corejsf/)p。 91意味着这两种方法应该是可以互换的。 – 2012-06-12 19:31:08

回答

0

我有一个类似的问题,我解决它定义为 “元数据” 的元数据集被˚F后立即注射:鉴于

<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>