• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to render different pages from the SelectOneMenu

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I am trying to find out a way to render different xhtml pages according to the selected value.

In my web it would be to render the page in a language or other depending of the value selected in the drop-down menu.

I tried the following:

In the XHTML I would use the UIComponent SelectOnMenu with different values related to the different languages.


And the Managed Bean:


This does not work. My question is how could I render the two differents XHTML according to the different option values of the UIComponent.


 
Ranch Hand
Posts: 514
1
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello!

You can use ajax for this!

You can create one big page that includes two parts. One part for one page and it is rendered by condition
<h:panelGroup rendered="#{backingBean.firstRendered">
</h:panelGroup>

Anothe part of the same page is rendered by:
<h:panelGroup rendered="#{! backingBean.firstRendered">
</h:panelGroup>

Clicking on h:selectonemenu option you call listener of f:ajax and set backingBean.firstRendered to true or false and in render attribute of f:ajax you specify main wrapper for both parts
 
Mikel Martin
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Many thanks for the answer.

As I am a newbie in J.S.F. I have been carefully examining your answer, but I got stucked in the last part of the answer (f:ajax).

I have written the following for the drop-down menu:



being english and spanish of the render attribute the id´s of the panel group when the firstRender method is false or true respectively.


But I can´t figure out how to make one or other render calling the firstRendered method in f:ajax

Many thanks
 
Saloon Keeper
Posts: 27752
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I haven't been able to use the f:ajax tag for technical reasons, so I am no expert, but it's possible that you may need to inform it what sort of event will fire the firstRendered method.

Try coding 'event="change"' on your f:ajax tag.
 
Bin Smith
Ranch Hand
Posts: 514
1
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello!

f:ajax you should set as this:

<f:ajax execute="@this" event="change" listener="#{languageControl.changePage}" render="yourFormID:english yourFormID:spanish" />

Your form should look like this



Your method listener inside LanguageControl backing bean should look similar to:


getter and setter of firstRendered property
 
Tim Holloway
Saloon Keeper
Posts: 27752
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Volodymyr, you might want to read this: https://coderanch.com/how-to/java/UseCodeTags
 
Bin Smith
Ranch Hand
Posts: 514
1
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Whenever I try to use code button it gives me some error.

In really rare situations I can apply it!
 
Tim Holloway
Saloon Keeper
Posts: 27752
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Volodymyr Levytskyi wrote:Whenever I try to use code button it gives me some error.

In really rare situations I can apply it!



What is "some error"

If you get the "Pants Down" error, that's because our database connection pool ran dry again and it has nothing to do with anything you did. We've been working hard on tuning connection usage lately.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic