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>
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555

2 Answers2

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.

Fritz
  • 9,987
  • 4
  • 30
  • 49
  • the problem that I have several jsf page and I have to display a single page – user2218876 Apr 12 '13 at 18:17
  • That's what the `...`'s are for in the example. You can place several `` 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. – Fritz Apr 12 '13 at 18:40
0

use a4j:outputpanel and inside it ui:include:

    <a4j:outputPanel rendered="#{someBean.someBoolean}">
        <ui:include src="somepage.xhtml" />
    </a4j:outputPanel>
Nick Russler
  • 4,608
  • 6
  • 51
  • 88