• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to render different pages from the SelectOneMenu

 
Mikel Martin
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • 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.


 
Volodymyr Lysenko
Ranch Hand
Posts: 511
1
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
Tim Holloway
Saloon Keeper
Pie
Posts: 17989
47
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • 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.
 
Volodymyr Lysenko
Ranch Hand
Posts: 511
1
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • 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
Pie
Posts: 17989
47
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Volodymyr, you might want to read this: http://www.coderanch.com/how-to/java/UseCodeTags
 
Volodymyr Lysenko
Ranch Hand
Posts: 511
1
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • 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
Pie
Posts: 17989
47
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic