[SEAM+RICHFACES] Problems using rich:togglePanel
demetrio812 Aug 26, 2007 8:46 AMHi,
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