使用jsf 2渲染页面标题

eRe*_*Rez 3 ajax jsf-2

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

<f:ajax render="@form">
Run Code Online (Sandbox Code Playgroud)

我试图将一个ID添加到h:head标记,并将该ID添加到f:ajax标记的'render'属性,但是如果这样做,则在页面加载时出现错误-

<f:ajax> contains an unknown id 'pageHead' - cannot locate it in the context of the component B1
Run Code Online (Sandbox Code Playgroud)

欢呼声,eRez

Fal*_*lup 5

有趣的问题。我认为在ajax渲染(例如@form)中没有这样的命令可以重新渲染页面标题。你可以做的是包装<title>用<h:form>或其他“分组”组件(例如,h:panelGroup像这样的丹尼尔说):

    <h:form id="titleForm">
        <title>#{fooBean.fooTitle}</title>
    </h:form>
Run Code Online (Sandbox Code Playgroud)

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

        <h:commandButton immediate="true" value="Change title">
            <f:ajax event="click" render=":titleForm"  listener="#{fooBean.changeTitle}"/>
        </h:commandButton>
Run Code Online (Sandbox Code Playgroud)

豆:

  private String fooTitle;

  public void changeTitle() {
        this.fooTitle= "updatedTitle";
  }
// getter/setter
Run Code Online (Sandbox Code Playgroud)

我不知道您还能做什么,这应该可以。因此,包装你title有<h:form id="...">,然后从阿贾克斯渲染。

  • 让我反对的是,页面顶部的h:form和h:panelGroup呈现的html是无效的html。有关使用`jsf.ajax.addOnEvent`的替代方法,请参见[此问题和答案](http://stackoverflow.com/questions/7566059/execute-javascript-after-ajax-update)。 (3认同)