java - How to update the model for a CheckBoxMultipleChoice? -


the classchoice control inherits checkboxmultiplechoice. common control used on multiple pages selections persisted in session. available choices obtained database. "all" checkbox added when there more 1 data item. on pages selection change causes page refreshed new data. on other page selections should change without refresh.

my problem need control "all" checkbox when other checkboxes change , change of checkboxes when "all" checkbox changes.

i tried call updatemodel() force change did not work. how can change selections (the model parameter) without refreshing page?

this edited code not show page refreshing.

public class classchoice<t> extends checkboxmultiplechoice {     private static final long serialversionuid = 1l;      @springbean     private classservice classservice;      list<entityclassmodel> selection;     entityclassmodel ecmall;      static list<entityclassmodel> availableclasses;      public classchoice(..)     {         super("classcheckboxes");          setsuffix(" "); // sets checkbox separator , ensures inline display          ecmall = (entityclassmodel) modelfactory.getnewclassmodel();         ecmall.setclassname("all");          // list of classes associated user         availableclasses = classservice.getlistofclasses(..);         setclasschoices();          add( new ajaxformchoicecomponentupdatingbehavior()         {             private static final long serialversionuid = 1l;              @override             protected void onupdate(ajaxrequesttarget target)             {                 list<integer> previousids = usersession.get().getselectedclassids();                 if ((previousids.size() > 0) && ((previousids.size() + 1)  >= availableclasses.size()))                 {                     // select                     if (selection.get(selection.size() - 1) == ecmall)                     {                         // select still selected, remove                         selection.remove(selection.size() - 1);                     }                     else                     {                         // remove selections                         selection.clear();                     }                 }                 else if (selection.size() > 0)                 {                     // none or selected                     if (selection.get(selection.size() - 1) == ecmall)                     {                         // select all, select available                         selection.clear();                         selection.addall(availableclasses);                     }                     else if ((selection.size() + 1) >= availableclasses.size())                     {                         // full, add select                         selection.add(ecmall);                     }                     // else change no special handling required                 }                 // else none selected                  usersession.get().setselectedclasses(selection);                  // generate list of selected class ids, excluding                 list<integer> selectedids = new arraylist<integer>();                 int copysize = selection.size();                 if ((copysize > 0) && (selection.get(copysize - 1) == ecmall))                 {                     copysize--;                 }                 (int index = 0; index < copysize; index++)                 {                     selectedids.add(selection.get(index).getid());                 }                 usersession.get().setselectedclassids(selectedids);                  // update selections on page                 updatemodel();             }                            });         initialize();     }      @suppresswarnings("unchecked")     protected void initialize()     {            // grabs selected classes usersession         list<integer> selectedids = usersession.get().getselectedclassids();         selection = classservice.getclassesbyclassids(selectedids);         if (selectedids.size() > 1)         {             if ((selectedids.size() + 1) >= availableclasses.size())             {                 selection.add(ecmall);             }         }         setmodel(model.oflist(selection));          // configure data , display         setchoicerenderer(new choicerenderer<entityclassmodel>("classname", "id"));         setoutputmarkupid(true);     }      @suppresswarnings("unchecked")     public void setclasschoices()     {         // adds 'all' option when there more 1 class         if (availableclasses.size() > 1)         {             availableclasses.add(ecmall);         }         setchoices(availableclasses);      }      public list<entityclassmodel> getselection()     {         return selection;     } } 

you have use ajaxrequesttarget update html element on browser side. adding/removing elements selection change model of classchoice @ server side. @ bottom of ajaxformchoicecomponentupdatingbehavior#onupdate() should target.add(this) tell wicket repaint classchoice instance new selection/model.

make sure call setoutputmarkupid(true) in constructor because otherwise won't able update ajax.


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -