【问题标题】:includeViewParams=true doesn't work in templated pagesincludeViewParams=true 在模板页面中不起作用
【发布时间】: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 并单击&lt;h:commandLink/&gt; 时,URL 更改为http://localhost:8080/faces/pages/test.xhtml。也就是说,视图参数不包含在重定向 URL 中。

但是,当我重构页面使其不使用模板时,它的行为符合预期。也就是说,视图参数包含在重定向 URL 中。

我了解&lt;f:metadata/&gt; 在放置在 facelets 模板中时不会也不应该工作。这不是这里发生的事情,所以这是一个不同的问题。规范中没有任何内容可以说这是无法做到的。确实,没有其他方法(据我所知)来创建带有视图参数的基于模板的页面。

【问题讨论】:

  • this bug添加了评论。
  • 我希望有一天能解决这个问题。我投了赞成票。
  • 我有一个与&lt;h:button /&gt;&lt;h:link /&gt; 类似的问题,其中包含includeViewParams="true" 属性不会产生与使用&lt;f:param /&gt; 条目重复视图参数相同的行为。当使用includeViewParams 时,链接/GET 请求中的参数值来自outcome 页面的支持bean,而不是来自提供给当前页面的视图参数,我认为它们应该是。 Core JavaServer Faces - Third Edition 页。 91 意味着这两种方法应该可以互换。

标签: java jsf-2 facelets post-redirect-get


【解决方案1】:

我有一个类似的问题,我将其解决为定义“元数据”集元数据在 f:view 之后立即被注入

<ui:define name="metadata">
   <f:metadata>
           <f:viewParam name="id" .../>
   </f:metadata>
    </ui:define>

模板.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>

【讨论】:

    猜你喜欢
    • 2017-10-14
    • 2021-01-02
    • 1970-01-01
    • 2018-03-05
    • 1970-01-01
    • 1970-01-01
    • 2014-05-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多