1 Reply Latest reply on Jan 21, 2012 11:19 PM by yamir73

    richface dynamic tree selection doesnt work

    yamir73

      I made page to create, update recursive records for dynamic tree based on example on internet (the example is made with spring, I changed that with seam framework), My problem is that the edit selection to get the information of current node is not working, return blank, but in the case adding new child the current selection that is the parent is working.  This is my xhtml:




             <h:panelGrid columns="2" columnClasses="coltopgroup,coltopgroup" width="70%">
                  <h:form>
                                <rich:panel id="dynamicTreePanel">
                                    <f:facet name="header">
                                       <h:outputText value="Account Tree" />                 
                                    </f:facet>
                                   
                                   <rich:tree ajaxSubmitSelection="true" ajaxSingle="true" 
                                              nodeSelectListener="#{accountTreeAction.processNodeSelection}"
                                              rightClickSelection="true"> 
                                                <rich:recursiveTreeNodesAdaptor roots="#{accountTreeBean.roots}" var="treeAccountRoot">
                                                  <rich:treeNode>
                                                    <h:outputText value="#{treeAccountRoot.description}"/>
                                                    
                                                    <rich:componentControl disableDefault="true" event="oncontextmenu" for="rootContextMenu" operation="show"/>
                                                  </rich:treeNode>
                                       
                                                  <rich:recursiveTreeNodesAdaptor roots="#{treeAccountRoot.childrenAccounts}"
                                                      var="treeAccountChild" nodes="#{treeAccountChild.childrenAccounts}">
                                       
                                                    <rich:treeNode>
                                                      <h:outputText value="#{treeAccountChild.description}"/>
                                                      
                                                      <rich:componentControl disableDefault="true" event="oncontextmenu" for="childContextMenu" operation="show"/>
                                                    </rich:treeNode>
                                                  </rich:recursiveTreeNodesAdaptor>
                                                </rich:recursiveTreeNodesAdaptor>
                                          </rich:tree>                            
                                </rich:panel> 
                                
                            <!-- context menu's -->
                            <rich:contextMenu id="rootContextMenu" attached="false" submitMode="ajax">
                              <rich:menuItem>
                                <h:outputText value="Add Child"/>
                       
                                <a:support event="onclick" action="addChild"
                                    reRender="dynamicTreePanel, addChildModalPanel"
                                    oncomplete="Richfaces.showModalPanel('addChildModalPanel')"/>
                              </rich:menuItem>
                              
                              <rich:menuSeparator/>
                       
                              <rich:menuItem>
                                <h:outputText value="Edit"/>
                       
                                <a:support event="onclick" action="editChild"
                                    reRender="dynamicTreePanel, editChildModalPanel"
                                    oncomplete="Richfaces.showModalPanel('editChildModalPanel')"/>
                              </rich:menuItem>
                            </rich:contextMenu>
                       
                            <rich:contextMenu id="childContextMenu" attached="false" submitMode="ajax">
                              <rich:menuItem>
                                <h:outputText value="Add Child"/>
                       
                                <a:support event="onclick" action="addChild"
                                    reRender="dynamicTreePanel, addChildModalPanel"
                                    oncomplete="Richfaces.showModalPanel('addChildModalPanel')"/>
                              </rich:menuItem>
                              
                              <rich:menuSeparator/>
                       
                              <rich:menuItem>
                                <h:outputText value="Edit"/>
                       
                                <a:support event="onclick"
                                    reRender="dynamicTreePanel, editChildModalPanel"
                                    oncomplete="Richfaces.showModalPanel('editChildModalPanel')"/>
                              </rich:menuItem>
                            </rich:contextMenu>
                       
                            <!-- modal panels -->
                            <rich:modalPanel id="addChildModalPanel"
                                resizeable="false" height="200" width="330">
                       
                              <f:facet name="header">
                                <h:outputText value="Add Account"/>
                              </f:facet>
                       
                              <h:panelGrid columns="2"
                                  columnClasses="verticalAlignTop">
                                <h:outputText value="Code:"/>
                                <h:inputText value="#{accountTreeAction.account.code}"/>
                                
                                <h:outputText value="Balance:" />
                                <h:inputText value="#{accountTreeAction.account.balance}" />
                       
                                <h:outputLabel value="Description:"/>
                                <h:inputText value="#{accountTreeAction.account.description}"/>
                              </h:panelGrid>
                       
                              <h:panelGroup style="display:block; text-align:center">
                                <a:commandButton action="#{accountTreeAction.saveAccount}" value="Ok"
                                    onclick="Richfaces.hideModalPanel('addChildModalPanel')"
                                    reRender="dynamicTreePanel, addChildModalPanel"
                                    styleClass="commandButton"/>
                       
                              </h:panelGroup>
                            </rich:modalPanel>  
                            
                            <rich:modalPanel id="editChildModalPanel"
                                resizeable="false" height="200" width="330">
                              <f:facet name="header">
                                <h:outputText value="Edit Account"/>
                              </f:facet>
                       
                              <h:panelGrid columns="2"
                                  columnClasses="verticalAlignTop">
                                <h:outputText value="Code:"/>
                                <h:inputText value="#{accountTreeAction.currentAccount.code}"/>
                                
                                <h:outputText value="Balance:" />
                                <h:inputText value="#{accountTreeAction.currentAccount.balance}" />
                       
                                <h:outputLabel value="Description:"/>
                                <h:inputText value="#{accountTreeAction.currentAccount.description}"/>
                              </h:panelGrid>
                       
                              <h:panelGroup style="display:block; text-align:center">
                                <a:commandButton action="#{accountTreeAction.updateAccount}" value="Ok"
                                    onclick="Richfaces.hideModalPanel('editChildModalPanel')"
                                    reRender="dynamicTreePanel, editChildModalPanel"
                                    styleClass="commandButton"/>            
                              </h:panelGroup>
                            </rich:modalPanel>                       
             </h:form>
                  
             </h:panelGrid>
      
      



      And these are my beans:



      @Name("accountTreeAction")
      @Scope(ScopeType.SESSION)
      @Restrict("#{identity.loggedIn}")
      @Transactional
      public class AccountTreeActionBean implements Serializable {
      
              private static final long serialVersionUID = 2329250819903907636L;
              
              @In private EntityManager entityManager;
              @In private User currentUser;
              
              private Account currentAccount;
              private Account account;
               
              public void processNodeSelection(NodeSelectedEvent event) {
                HtmlTree tree = ((HtmlTree) event.getComponent());     
                currentAccount = (Account)tree.getRowData();
              }
              
              public void setCurrentAccount(Account currentAccount) {
                      this.currentAccount = currentAccount;
              }
              
              public Account getCurrentAccount() {
                      return currentAccount;
              }
              
              public void cancelAccount() {
                      
              }
              
              @Transactional
           /* this works, the current account is selected */
              public void saveAccount() {
                      PartyJoin partyJoin = (PartyJoin) entityManager.createQuery("from PartyJoin p where p.id=:id")
                                                                 .setParameter("id", currentUser.getParty().getId())
                                                                 .getSingleResult();          
                      account.setParty(partyJoin);
                      account.setParentAccount(currentAccount);
                      entityManager.persist(account); 
                      account = null;
              }
              
              @Transactional
           /* this don't work, the current account is null */
              public void updateAccount() {
                      entityManager.merge(currentAccount);
              }
              
              public Account getAccount() {
                      if ( account == null ) {
                              account = new Account();
                      }
                      return account;
              }
              
              public void setAccount(Account account) {
                      this.account = account;
              }
      
      To simplify the code this is my entity bean without other columns:
      @Entity
      @Table(name = "account", catalog = "account")
      public class Account implements java.io.Serializable {
      
              private static final long serialVersionUID = -8863060453596635556L;
              private Long id;
              private PartyJoin party;
              private Account parentAccount;
              private String description;
              private List<Account> childrenAccounts = new ArrayList<Account>();
      
              public Account() {
              }
      
              public Account(Account account) {
                      this.parentAccount = account;
              }
      
              @Id
              @GeneratedValue(strategy = IDENTITY)
              @Column(name = "id", unique = true, nullable = false)
              public Long getId() {
                      return this.id;
              }
      
              public void setId(Long id) {
                      this.id = id;
              }
              
              @ManyToOne(fetch = FetchType.LAZY)
              @JoinColumn(name = "party_id")
              public PartyJoin getParty() {
                      return this.party;
              }
      
              public void setParty(PartyJoin party) {
                      this.party = party;
              }
      
              @ManyToOne(fetch = FetchType.LAZY)
              @JoinColumn(name = "account_id")
              public Account getParentAccount() {
                      return this.parentAccount;
              }
      
              public void setParentAccount(Account account) {
                      this.parentAccount = account;
              }
      
              @OneToMany(fetch = FetchType.LAZY, mappedBy = "parentAccount")
              public List<Account> getChildrenAccounts() {
                      return this.childrenAccounts;
              }
      
              public void setChildrenAccounts(List<Account> accounts) {
                      this.childrenAccounts = accounts;
              }
              
      }
      
      
      



        • 1. Re: richface dynamic tree selection doesnt work
          yamir73

          I added the following componet between both modal panel (add, edit) and now is working:



          <a:outputPanel ajaxRendered="true" layout="block">
          <rich:modalPanel id="editChildModalPanel" resizeable="false" height="200" width="330">
          ....
          </a:outputPanel>



          I would like to know why with this component is working and without this doents works.