includeViewParams = true在模板化页面中不起作用

时间:2020-12-06 20:06:19

Consider this template:

考虑这个模板:

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

this page that uses it (/pages/test.xhtml):

这个使用它的页面(/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>

the page's bean:

页面的bean:

@Named
@RequestScoped
public class PageBean implements Serializable
{
    public String getFoo()
    {
        return foo;
    }

    public void setFoo(String foo)
    {
        this.foo = foo;
    }

    private String foo;
}

and this bean:

而这个豆子:

@Named
@ApplicationScoped
public class Util implements Serializable
{
    public String currentPageAction()
    {
        return FacesContext.getCurrentInstance().getViewRoot().getViewId() +
                   "?faces-redirect=true&includeViewParams=true";
    }
}

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.

当我在浏览器中加载http:// localhost:8080 / faces / pages / test.xhtml?foo = bar并单击 时,URL将更改为http:// localhost:8080 / faces / pages /test.xhtml。也就是说,视图参数不包含在重定向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.

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

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.

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

1 个解决方案

#1


0  

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

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

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

#1


0  

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

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

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