【问题标题】:render page title using jsf 2使用 jsf 2 渲染页面标题
【发布时间】:2012-04-27 04:12:11
【问题描述】:

有没有办法将页面标题包含在f:ajax 标记中,以便在运行时更新其内容? 目前我的 f:ajax 标签看起来像这样 -

<f:ajax render="@form">

我尝试将 id 添加到 h:head 标记,并将该 id 添加到 f:ajax 标记的 'render' 属性,但如果这样做,我会在页面加载时收到错误 -

<f:ajax> contains an unknown id 'pageHead' - cannot locate it in the context of the component B1

干杯, 埃雷兹

【问题讨论】:

    标签: ajax jsf-2


    【解决方案1】:

    有趣的问题。我认为在 ajax 的渲染(如@form)中没有这样的命令来重新渲染页面标题。您可以做的是将&lt;title&gt; 与&lt;h:form&gt; 或其他“分组”组件(例如丹尼尔所说的h:panelGroup)包装在一起:

        <h:form id="titleForm">
            <title>#{fooBean.fooTitle}</title>
        </h:form>
    

    然后调用 ajax 更新例如。带按钮:

            <h:commandButton immediate="true" value="Change title">
                <f:ajax event="click" render=":titleForm"  listener="#{fooBean.changeTitle}"/>
            </h:commandButton>
    

    豆子:

      private String fooTitle;
    
      public void changeTitle() {
            this.fooTitle= "updatedTitle";
      }
    // getter/setter
    

    我不知道你还能做什么,这应该可以。所以用&lt;h:form id="..."&gt; 包装你的title,然后从ajax 渲染它。

    【讨论】:

    • 有“@all”但没有比“@form”特别的功能
    • @Ravi 是的,我知道有“@all”。我只是想说没有与渲染页面标题相关的标签。
    • 你不必用
      就足够了......因为无论如何 h:commandButton 都会被包裹以它的形式
    • @Daniel 澄清一下,我的意图是展示一些组件的包装。我选择表单的事实与 commandButton 无关 - 例如,它只是在我脑海中突然出现。您对 h:panelGroup 的看法是对的,这就足够了。感谢您的评论,我将编辑答案
    • 让我反对来自页面头部部分的h:form 和h:panelGroup 呈现的html 不是有效的html。有关使用 jsf.ajax.addOnEvent 的替代方法,请参阅 this question and answer。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-20
    • 2018-04-04
    • 1970-01-01
    • 2011-08-14
    • 2011-09-28
    • 2023-04-03
    相关资源
    最近更新 更多