jsf - After a single element is removed from DB, it is still rendered in p:tree, until I either change another element or refresh the page -


i'm having trouble trying update list of elements contained in primefaces p:tree through ajax. problem i'm facing is: after single element removed database still rendered in tree, until either change element (causing update of p:tree component) or refresh page.

there 2 managed beans involved in process:

1- first responsible populating tree entites contained in database, here's relevant code:

@named @requestscoped public class credentialprovider {      @inject     private userfacadelocal userfacade;      private treenode usercredentials;      @postconstruct     public void init() {         /* uses facade populate treenode entities */     }              public treenode getusercredentials(){         return usercredentials;     }      /* other getters , setters */  } 

2- second responsible updating / deleting entities, here's code:

@named @requestscoped public class credentialmanager {      @inject     private userfacadelocal userfacade;      public void deletecredential(string userid){         user user = userfacade.find(userid);         userfacade.remove(user);     }      /* other entitie handling methods */ } 

the action of remvoing element triggered by:

<p:commandbutton value="delete" update=":treecontainer" actionlistener="#{credentialmanager.deletecredential(node.login)}" 

when click button see @postconstructof credentialprovider bean being called first, , right after getusercredentials() method, , after deletecredential() called.

so tree contents being generated before they're updated, how can solve this?

the credentialprovider being constructed first because that's needed in order let jsf find item delete can supply right id deletecredential() method.

just explicitly reinitialize model after update.

@named @requestscoped public class credentialmanager {      @inject     private userfacadelocal userfacade;      @inject     private credentialprovider credentialprovider;      public void deletecredential(string userid){         user user = userfacade.find(userid);         userfacade.remove(user);         credentialprovider.init();     }      /* other entitie handling methods */ } 

you might want change scope of credentialprovider @viewscoped keep alive across postbacks can ensure integrity across postbacks when database been manipulated other requests in meanwhile. additional bonus is, saves unnecessary queries db.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -