使用jsf 2呈现页面标题

时间:2012-04-15 16:29:24

标签: ajax jsf-2

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

<f:ajax render="@form">

我试图在h:head标签中添加一个id,并将该id添加到f:ajax标签的'render'属性中,但如果我这样做,我会在页面加载时出错 -

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

欢呼声, 埃雷兹

1 个答案:

答案 0 :(得分:5)

有趣的问题。我认为在渲染ajax(如@form)时没有这样的命令来重新呈现页面标题。您可以做的是将<title><h:form>或其他“分组”组件包裹起来(例如。h:panelGroup,如Daniel所说),如下所示:

    <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

我不知道你还能做什么,这应该有效。然后用title包裹<h:form id="...">,然后从ajax中渲染它。

相关问题