Forums Register Login

How to render different pages from the SelectOneMenu

+Pie Number of slices to send: Send
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.


+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
Volodymyr, you might want to read this: https://coderanch.com/how-to/java/UseCodeTags
+Pie Number of slices to send: Send
Whenever I try to use code button it gives me some error.

In really rare situations I can apply it!
+Pie Number of slices to send: Send
 

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.
Remember to always leap before you look. But always take the time to smell the tiny ads:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 3794 times.
Similar Threads
Jrame not visible when Try to run from Unit Test
usage of "this"
JSF 2.0 MyConverter.getAsObject(...) how to get a handle on the backing bean
Which Design Pattern and how to design using OOP this scenaria
PGPPublicKeyRingCollection doubts
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 17:35:15.