includeViewParams = true在模板化页面中不起作用 [英] includeViewParams=true doesn't work in templated pages

查看:146
本文介绍了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):

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>

页面的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=bar 在浏览器中点击< h:commandLink /> ,URL更改为 http:// localhost:8080 / faces / pages / test.xhtml 。也就是说,视图参数不包含在重定向URL中。

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.

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

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.

推荐答案

我有一个类似的问题,我把它解决为定义元数据集元数据在f之后立即注入:视图

I have a similar issue,i resolve it as define "metadata" set Metadata gets injected right after f:view

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

template.xhtml

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>

这篇关于includeViewParams = true在模板化页面中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆