GWT Header CheckBox requires two clicks to fire setValue, after changing its value programatically -


i have gwt datagrid, , checkbox in header select/deselect rows in grid.

the code checkbox header follows:

    private class checkboxheader extends header<boolean> implements hasvalue<boolean> {      private boolean checked;     private handlermanager handlermanager;      /**      * html string representation of checked input box.      */     private final safehtml input_checked = safehtmlutils.fromsafeconstant("<input type=\"checkbox\" tabindex=\"-1\" checked/>");     /**      * html string representation of unchecked input box.      */     private final safehtml input_unchecked = safehtmlutils.fromsafeconstant("<input type=\"checkbox\" tabindex=\"-1\"/>");      @override     public void render(context context, safehtmlbuilder sb) {         if (boolean.true.equals(this.getvalue())) {             sb.append(input_checked);         } else {             sb.append(input_unchecked);         }     };      public checkboxheader() {         super(new checkboxcell(true, false));         checked = true;     }      // method invoked pass value checkboxcell's render method     @override     public boolean getvalue() {         return checked;     }      @override     public void onbrowserevent(context context, element elem, nativeevent nativeevent) {         int eventtype = event.as(nativeevent).gettypeint();         if (eventtype == event.onchange) {             nativeevent.preventdefault();             // use value setter fire change event handlers             setvalue(!checked, true);         }     }      @override     public handlerregistration addvaluechangehandler(valuechangehandler<boolean> handler) {         return ensurehandlermanager().addhandler(valuechangeevent.gettype(), handler);     }      @override     public void fireevent(gwtevent<?> event) {         ensurehandlermanager().fireevent(event);     }      @override     public void setvalue(boolean value) {         setvalue(value, true);     }      @override     public void setvalue(boolean value, boolean fireevents) {         checked = value;         if (fireevents) {             valuechangeevent.fire(this, value);         }     }      private handlermanager ensurehandlermanager() {         if (handlermanager == null) {             handlermanager = new handlermanager(this);         }         return handlermanager;     } } 

so, add header grid, , add valuechangehandler actual selecting/deselecting of individual checkbox cells in every row of grid. works.

every checkboxcell has field updater, , on every update loops through every item in grid see if checked, , update header check box. if @ least 1 unchecked, header checkbox unchecked. call setvalue() on header check box, , after call redrawheaders() on entire grid. works.

what doesn't work - after changing "state" of header check box programatically, takes 2 clicks fire it's internal setvalue again, , therefore trigger handler. , what's funnier - first click does change state of check box, doesn't fire event.

any appreciated.

how constructing checkboxcells themselves? ran similar issue column of checkboxes "eating" clicks, , solution call checkboxcell cell = new checkboxcell(true,true) , pass cell constructor of column.


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

How to get multiresult with multicondition in Sql Server -