8 Replies Latest reply on Mar 22, 2012 3:07 PM by Rogério Napoleão Jr

    Problem with ViewScoped JSF2 and render Richfaces 4.2

    Rogério Napoleão Jr Newbie

      Hi everyone,

       

      The code

       

      teste.xhtml

       

       

      <h:head>
        <title>Teste</title>
      </h:head>
      <h:body>    
      
          <rich:panel id="teste_panel"> 
      
          <a4j:outputPanel rendered="#{teste.testeStr == 'teste2' or teste.testeStr == null}"> 
               <h:form>
                  <a4j:commandButton value="Teste1" action="#{teste.teste1}" render="teste_panel"/>
              </h:form>
          </a4j:outputPanel>
      
          <a4j:outputPanel rendered="#{teste.testeStr == 'teste1' or teste.testeStr == null}">
              <h:form>
                  <a4j:commandButton value="Teste2" action="#{teste.teste2}" render="teste_panel"/>
              </h:form>
          </a4j:outputPanel>
      
           <a4j:outputPanel rendered="#{teste.testeStr == null}">
                oi
           </a4j:outputPanel>
           <h:outputText value="#{teste.testeStr}"/>
      
          </rich:panel>
      </h:body>
      

       

      and

       

      TesteManagedBean

       

      import javax.annotation.PostConstruct;
      import javax.faces.bean.ManagedBean;
      import javax.faces.bean.ViewScoped;
      
      @ManagedBean(name = "teste")
      @ViewScoped
      public class TesteManagedBean {
      
          private String testeStr;
      
          public String getTesteStr() {
              return testeStr;
          }
      
          public void setTesteStr(String testeStr) {
              this.testeStr = testeStr;
          }
      
          @PostConstruct
          public void postConstruct(){
              System.out.println("Construct");
          }
      
          public void teste1(){
              testeStr = "teste1";
              System.out.println("Teste1");
          }
      
          public void teste2(){
              testeStr = "teste2";
              System.out.println("Teste2");
          }
      }
      

       

      By clicking on the buttons Test1 and Test2 content should be written to the console:

      Construct

      Teste1

      Teste2

       

      but this is not what happens, writes:

      Construct

      Teste1

      Construct

       

      by clicking on the Test2 he calls the constructor again.

      Does anyone know how can I be solving?