3 Replies Latest reply on Aug 27, 2007 5:01 AM by ilya_shaikovsky

    [SEAM+RICHFACES] Problems using rich:togglePanel

    demetrio812

      Hi,
      today I had a problem in Seam using the togglePanel component, in simple words I have a toggle panel with 2 states, the first has just 1 link, if I click it will switch to an edit input control and a button to save the control.
      When I click the first button I set the bean to edit (that is null at first) but when I try to save it I get a NPE like as the conversation was closed.

      This is my code:

      view:

      <rich:togglePanel id="gctp" switchType="client" stateOrder="txt,edit" >
       <f:facet name="txt">
       <h:panelGroup>
       <rich:toggleControl for="gctp">
       <a:commandLink value="Aggiungi gruppo" action="#{homepageHelper.preparaAggiuntaGruppo}"></a:commandLink>
       </rich:toggleControl>
       </h:panelGroup>
       </f:facet>
       <f:facet name="edit">
       <h:panelGroup>
       <h:outputText value="Gruppo: "></h:outputText>
       <h:inputText value="#{homepageHelper.gruppoEdit.descrizione}"></h:inputText>
       <rich:toggleControl for="gctp">
       <a:commandLink action="#{homepageHelper.salvaGruppo}" value="Salva" />
       </rich:toggleControl>
       </h:panelGroup>
       </f:facet>
      </rich:togglePanel>
      


      bean (Scope=CONVERSATION):

      @Name("homepageHelper")
      @Scope(ScopeType.CONVERSATION)
      public class HomepageHelper implements Serializable {
      
       private Gruppo gruppoEdit; // gruppo usato per l'aggiunta o la modifica
      
       public Gruppo getGruppoEdit() {
       if (gruppoEdit==null) {
       gruppoEdit=new Gruppo();
       System.out.println("NEWGET");
       System.out.println("HPH: "+this);
       }
       System.out.println("GET");
       return gruppoEdit;
       }
      
       public void setGruppoEdit(Gruppo gruppoEdit) {
       System.out.println("SET: "+gruppoEdit);
       System.out.println("HPH: "+this);
       this.gruppoEdit = gruppoEdit;
       }
      
       public void preparaAggiuntaGruppo() {
       Gruppo g = new Gruppo();
       g.setContatto(loggedUserManager.getLoggedUser());
       g.setDescrizione("nuovo");
       System.out.println("pag");
       setGruppoEdit(g);
       }
      
       public void preparaModificaGruppo() {
       setGruppoEdit(getGruppoSelezionato());
       }
      
       public void salvaGruppo() {
       // Se sono in modifica
       System.out.println("GE: "+getGruppoEdit().getDescrizione());
       System.out.println("HPH: "+this);
       /*if (entityManager.contains(getGruppoEdit())) {
       entityManager.merge(getGruppoEdit());
       } else {
       entityManager.persist(getGruppoEdit());
       }
       entityManager.flush(); // Salvo
       */
       }
      
       ...
      


      where do I wrong?

      I noticed during my tests that the conversation object HomepageHelper has different instances between switching.

      Also I tried to do now use togglePanel and it works, like that:

      <a:form id="gcform">
      <a:commandLink value="Aggiungi gruppo" action="#{homepageHelper.preparaAggiuntaGruppo}" reRender="gcform"></a:commandLink>
       <h:outputText value="Gruppo: "></h:outputText>
       <h:inputText value="#{homepageHelper.gruppoEdit.descrizione}"></h:inputText>
       <a:commandLink action="#{homepageHelper.salvaGruppo}" value="Salva" reRender="gcform"/>
      </a:form>
      


      I don't know if it is a seam problem or a richfaces problem (or my problem :D) so I post this in both the forums...

      thanks

      Demetrio Filocamo

        • 1. Re: [SEAM+RICHFACES] Problems using rich:togglePanel
          demetrio812

          Sorry I posted the wrong beans code (it was the one after some tests :P)..

          this is the right one:

          @Name("homepageHelper")
          @Scope(ScopeType.CONVERSATION)
          public class HomepageHelper implements Serializable {
          
           private Gruppo gruppoEdit; // gruppo usato per l'aggiunta o la modifica
          
           public Gruppo getGruppoEdit() {
           return gruppoEdit;
           }
          
           public void setGruppoEdit(Gruppo gruppoEdit) {
           this.gruppoEdit = gruppoEdit;
           }
          
           public void preparaAggiuntaGruppo() {
           Gruppo g = new Gruppo();
           g.setContatto(loggedUserManager.getLoggedUser());
          
           setGruppoEdit(g);
           }
          
           public void salvaGruppo() {
           // Se sono in modifica
           if (entityManager.contains(getGruppoEdit())) {
           entityManager.merge(getGruppoEdit());
           } else {
           entityManager.persist(getGruppoEdit());
           }
           entityManager.flush(); // Salvo
           }
          
           ...
          


          Demetrio

          • 2. Re: [SEAM+RICHFACES] Problems using rich:togglePanel
            demetrio812

            togglePanel gave me a lot of problems while trying to make it works in ajax mode: sometime panel would not switch and reRender between switch states doesn't seem to work...

            doesn someone know something about it?

            Maybe I can make a deployable example to test it (maybe it's wrong my way of doing)...


            Demetrio

            • 3. Re: [SEAM+RICHFACES] Problems using rich:togglePanel
              ilya_shaikovsky

              Why are you using a4j:links inside toggle controls? At first toggleControl - encodes as link so no need to use link inside. Just specify the same properties in the control. Second any way - you have specified client switch mode - so toggle panel will be switched on the client without additional server processing