3

is there any way to include the page's title inside an f:ajax tag, so that its content is also updated at run time? currently my f:ajax tag looks like this -

<f:ajax render="@form">

i tried to add an id to the h:head tag, and add that id to the 'render' property of the f:ajax tag, but if i do so i get an error when the page loads -

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

cheers, eRez

1 Answer 1

5

Interesting question. I think there is no such command in render of ajax (like @form) to re-render the page title. What you can do is to wrap <title> with <h:form> or other "grouping" component (eg. h:panelGroup as Daniel said) like this :

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

And then call ajax update eg. with button :

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

Bean:

  private String fooTitle;

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

I don't know what else could you do, this should work. So wrap your title with <h:form id="..."> and then render it from ajax.

6
  • there is "@all" but does nothing special than "@form" Apr 15, 2012 at 18:16
  • @Ravi Yes I know that there is "@all". I just wanted to say there is no tag related to rendering the page title.
    – Fallup
    Apr 15, 2012 at 18:18
  • 1
    You don't have to wrap the tile with <h:form , a simple <h:panelGroup id="titleWrapperID"> will be enough... cause anyway the h:commandButton will be wrapped in its form
    – Daniel
    Apr 15, 2012 at 19:02
  • @Daniel Just to clarify, my intent was to show wrapping with some component. The fact I chose form has nothing to do with commandButton - which is there just for example - it just popped in my head as first thing. You are right about h:panelGroup, it's enough. Thank you for comment I will edit answer
    – Fallup
    Apr 15, 2012 at 19:11
  • 3
    Let me object that the rendered html from h:form and h:panelGroup inside the head section of a page are not valid html. See this question and answer for a alternative approach using jsf.ajax.addOnEvent.
    – Matt Handy
    Apr 15, 2012 at 19:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.