2

My Ajax codes for rendering a form using a newly-selected locale are:

<h:selectOneMenu id="selectLang" immediate="true" value="#{langListing.language}">
   <f:ajax listener="#{langListing.changeLocale}" render="@form" />
   <f:selectItems value="#{langListing.languages}" />
</h:selectOneMenu>

However, since the above codes in in a header file called header.xhtml, the above codes only render the content of header.xhtml when I switch locales between English and French. My index.xhtml structure is as follow:

header.xhtml
menu.xhtml
body content with an id of "contentSection"
footer.xhtml

How can I render menu.xhtml, the body section and footer.xhtml at the same time as I render header.xhtml?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
ChuongPham
  • 4,761
  • 8
  • 43
  • 53

1 Answers1

3

The @form affects the content of parent <h:form> only. Use @all instead.

<f:ajax listener="#{langListing.changeLocale}" render="@all" />

See also the description of the render attribute in <f:ajax> tag documentation.

However, since changing the locale affects the entire page anyway, you could also consider to fire a synchronous request instead of an ajaxical one. To achieve this, remove the <f:ajax> tag, add a onchange="submit()" to the dropdown and move the code inside changeLocale() into setLanguage() method. See also this answer for a concrete example.

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • I'll have a look at the link and will get back to you. – ChuongPham Feb 17 '11 at 18:26
  • That example is of sound programming. It works like a charm. Again, you're the man, BalusC!!! – ChuongPham Feb 17 '11 at 18:35
  • I have just recommended several of my programming mates to this site and, of course, **balusc.blogspot.com**. You guys rock!!! Before my mates and I were on Roseindia website but it was crap and ads-laden. Now, I'm feeling happy to be at **stackoverflow**. Thanks so much... – ChuongPham Feb 17 '11 at 18:55
  • Truly Roseindia is crap. I am [aware](http://balusc.blogspot.com/2008/06/what-is-it-with-roseindia.html) about this as well :) – BalusC Feb 17 '11 at 18:56