*
The moose likes JSF and the fly likes How to render different pages from the SelectOneMenu Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "How to render different pages from the SelectOneMenu" Watch "How to render different pages from the SelectOneMenu" New topic
Author

How to render different pages from the SelectOneMenu

Mikel Martin
Greenhorn

Joined: Nov 15, 2012
Posts: 8
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 Levytskyi
Ranch Hand

Joined: Mar 29, 2012
Posts: 505
    
    1

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


True person is moral, false is right!
Mikel Martin
Greenhorn

Joined: Nov 15, 2012
Posts: 8
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

Joined: Jun 25, 2001
Posts: 16020
    
  20

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
Volodymyr Levytskyi
Ranch Hand

Joined: Mar 29, 2012
Posts: 505
    
    1

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

Joined: Jun 25, 2001
Posts: 16020
    
  20

Volodymyr, you might want to read this: http://www.coderanch.com/how-to/java/UseCodeTags
Volodymyr Levytskyi
Ranch Hand

Joined: Mar 29, 2012
Posts: 505
    
    1

Whenever I try to use code button it gives me some error.

In really rare situations I can apply it!
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16020
    
  20

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to render different pages from the SelectOneMenu