1

I've a problem when I use selectOneRadio and the renderer of my panels.

My cession.xhtml contains this

    <p:selectOneRadio id="options" value="#{editionBean.radioProprietaire}">
      <f:selectItem itemLabel="Particulier" itemValue="particulier" />
      <f:selectItem itemLabel="Societe" itemValue="societe" />
      <f:ajax listener="#{editionBean.listener}"/>
    </p:selectOneRadio>

    <h:panelGroup rendered="#{editionBean.renderSoc}">...</h:panelGroup>
    <h:panelGroup rendered="#{editionBean.renderPart}">...</h:panelGroup>

My EditionBean.class

private boolean renderSoc;
private boolean renderPart;
private String radioProprietaire;

public void listener(AjaxBehaviorEvent event) {
  if(null != radioProprietaire && radioProprietaire.equals("particulier")){
           renderPart = true;
       renderSoc = false;
      }
  else if(null != radioProprietaire && radioProprietaire.equals("societe")){
    renderPart = false;
    renderSoc = true;
      }
  }

I know that method listener is call, but ths panels aren't visible, if someone can help me ?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
wamdeus
  • 13
  • 1
  • 6

2 Answers2

4

There are 2 problems.

  1. You need <p:ajax> instead of <f:ajax> in PrimeFaces components.

  2. You need to explicitly specify a JSF component in the ajax update so that it will be re-rendered. With the current approach, you're basically updating nothing. With <f:ajax>, the to-be-updated components should be specified in render attribute and with <p:ajax> in update attribute.

Further, there's some inefficiency going on. You don't need the listener method and those lot of boolean properties at all. You can just check the radio button value directly in the rendered attribute.

So, all with all, this should do:

<p:selectOneRadio id="options" value="#{editionBean.radioProprietaire}">
    <f:selectItem itemLabel="Particulier" itemValue="particulier" />
    <f:selectItem itemLabel="Societe" itemValue="societe" />
    <p:ajax update="groups" />
</p:selectOneRadio>

<h:panelGroup id="groups">
    <h:panelGroup rendered="#{editionBean.radioProprietaire == 'societe'}">
        ...
    </h:panelGroup>
    <h:panelGroup rendered="#{editionBean.radioProprietaire == 'particulier'}">
        ...
    </h:panelGroup>
</h:panelGroup>

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Can I change my file editionBean ? or web.xml or another config file ? – wamdeus Jan 19 '13 at 15:33
  • You have only to remove unused properties and unused listener method. – BalusC Jan 19 '13 at 15:58
  • Yes my bean contains only attributs and its getters and setters only (I can't post my code because i need 10 in reputations ^^) – wamdeus Jan 19 '13 at 16:06
  • Here, you can see my code http://hubertpicardat.fr/sites/edition.xhtml.txt http://hubertpicardat.fr/sites/edition.java.txt – wamdeus Jan 19 '13 at 16:32
  • What are all those `` doing there in your view? Remove them. Further, please descibe your concrete problem clearly. The above answer should solve your problem, but you have never explicitly confirmed nor denied the solution. – BalusC Jan 19 '13 at 17:38
  • Ohh thank a lot @BalusC, when I delete my , my panels appear. Thank you !!!! you're the best ! thanks you Luiggi too !! StackOverFlow is wonderfull – wamdeus Jan 19 '13 at 18:20
1

As explained in this answer, you should wrap the <h:panelGroup> component inside an UIContainer and render that bigger container in order to make the panel to become visible:

<p:selectOneRadio id="options" value="#{editionBean.radioProprietaire}">
  <f:selectItem itemLabel="Particulier" itemValue="particulier" />
  <f:selectItem itemLabel="Societe" itemValue="societe" />
  <p:ajax listener="#{editionBean.listener}" render="pnlSoc pnlPart" />
</p:selectOneRadio>

<h:panelGrid id="pnlSoc">
    <h:panelGroup rendered="#{editionBean.renderSoc}">...</h:panelGroup>
</h:panelGrid>
<h:panelGrid id="pnlPart">
    <h:panelGroup rendered="#{editionBean.renderPart}">...</h:panelGroup>
</h:panelGrid>
Community
  • 1
  • 1
Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332