0

I hope you can help me. I work with jsf and richefaces, I have a jsf page and I want to include all other pages according to a parameter and my problem is how can I introduce the test condition in my xhtml file.

THanks for your response, there is my code but it does not work, my bean

 public class TestBean { private boolean ajoutH; private boolean listH; public boolean isListH() { FacesContext fc = FacesContext.getCurrentInstance(); Map<String,String> params = fc.getExternalContext().getRequestParameterMap(); String id = params.get("listH"); if(id.equals("listH")){ return true;} else{ return false; } } public boolean isAjoutH() { FacesContext fc = FacesContext.getCurrentInstance(); Map<String,String> params = fc.getExternalContext().getRequestParameterMap(); String id = params.get("ajoutH"); if(id.equals("ajoutH")){ return true;} else{ return false;} 

And my page jsf

<rich:panelMenuGroup label="Hotes"> <rich:panelMenuItem> <h:outputText value="Ajouter Hote" event="onclick"> <f:param value="{ajoutH}" name="ajoutH" /> </h:outputText> </rich:panelMenuItem> <rich:panelMenuItem > <h:outputText value="Gérer Hotes" > <f:param value="{listH}" name="listH" /> </h:outputText> ...... <h:panelGroup rendered="#{TestBean.ajoutH}"> <ui:include src="./ajoutHote.xhtml"/> </h:panelGroup> <h:panelGroup rendered="#{TestBean.listH}"> <ui:include src="./listHotes.xhtml"/> </h:panelGroup> 
0

2 Answers 2

2

There are different options here and since you're using richfaces I'll include an example for that one too.

If you go for a pure JSF approach, use an <h:panelGroup> with a rendered attribute on it, defined by your bean. This attribute must be a boolean.

<h:panelGroup rendered="#{yourBean.yourCondition}"> <ui:include src="pages/yourPage.xhtml"> ... </h:panelGroup> 

Another option is to use an <a4j:region>. It works in the same way basically.

<a4j:region rendered="#{yourBean.yourCondition}"> <ui:include src="pages/yourPage.xhtml"> ... </a4j:region> 

Regardless of your choice, your bean should define the condition:

public Boolean isYourCondition() { return /*your logic here*/; } 

There are many approaches to take, just take your pick.

Sign up to request clarification or add additional context in comments.

2 Comments

the problem that I have several jsf page and I have to display a single page
That's what the ...'s are for in the example. You can place several <ui:include/> elements in a single page. They'll be included in the order you define. I assume you have the UI design covered. Should you need to check DIFFERENT conditions for each include, you just need to encase each one of them in a different region or panel group with the proper rendered attribute.
0

use a4j:outputpanel and inside it ui:include:

 <a4j:outputPanel rendered="#{someBean.someBoolean}"> <ui:include src="somepage.xhtml" /> </a4j:outputPanel> 

2 Comments

the problem that I have several jsf page and I have to display a single page
You can include several pages with the ui:include into one page. Take a look at this.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.