datenhahn / componentrenderer

A ComponentRenderer for the Vaadin Grid
Apache License 2.0
6 stars 8 forks source link

Checkbox cannot be checker or unchecked #12

Closed Fluffysandals closed 8 years ago

Fluffysandals commented 8 years ago

I tried to use ComponentRenderer with a Checkbox but the checkbox value cannot be changed by clicking the checkbox : nothing happens.

I have a valuechangelistener on the checkbox, but it is actually never entered when clicking the checkbox.

Another problem is that the checkbox is not centered, but sits on the top left of the cell, and I cannot figure a way to have it centered. (It has a defined width and height)

datenhahn commented 8 years ago

Bug confirmed

datenhahn commented 8 years ago

Somehow the Grid focus and header click event listener seem to interfere with the checkbox logic. The clickevent which would call the rpc for the valuechangelistener and update the state is fired but it never enters this conditional because before is a check which verifies that indeed the value has changed. Some

Vaadin is styling the checkbox by using a label and the clickevents are fired two times, that's why the built the double check into it to prevent unnecessary rpcs.

So in my test the sharedState's checkbox value was false, but after the click the widget's value should be true. Somehow it isn't. I see the grid focus blink when I click and the checkbox also seem to interfere with header clicks.

VCheckBox Clickhandler: public void onClick(ClickEvent event) { if(this.isEnabled()) { if(this.getState().checked != this.getWidget().getValue().booleanValue()) { this.getState().checked = this.getWidget().getValue().booleanValue(); MouseEventDetails details = MouseEventDetailsBuilder.buildMouseEventDetails(event.getNativeEvent(), this.getWidget().getElement()); ((CheckBoxServerRpc)this.getRpcProxy(CheckBoxServerRpc.class)).setChecked(this.getState().checked, details); if(this.getState().immediate) { this.getConnection().sendPendingVariableChanges(); } }

    }
}

GWT CheckBox getValue():

     public Boolean getValue() {
    return this.isAttached()?Boolean.valueOf(this.inputElem.isChecked()):Boolean.valueOf(this.inputElem.isDefaultChecked());
}
Fluffysandals commented 8 years ago

My current workaround to this problem is using a label with a fontawesome icon (check_square_o when true and square_o when false), in an horizontallayout on which I added a clicklistener. Works the same way a checkbox would work, just a bit more extra code.

datenhahn commented 8 years ago

Almost there, I just went through a hell of event debugging, just to discover two things to investigate:

I will update the renderer and release a new version soon

datenhahn commented 8 years ago

Thanks for your bugreport, this sure was a serious one. Before going beta I will add some tests to at least catch bugs with the most commonly used components.

I just uploaded the fixed version, please make sure you also use the addons.scss in your own theme which sets the needed stylings for centering the checkbox and reload in a private-browser-tab or make sure the cache is cleared.

I renamed the component-renderers-class to cr-component-cell to have a unique prefix.

I added the checkbox to all demo-grids which use the convenience wrapper, so just browse to tab 2,3,4 of the demo to see a checkbox in action.

And reopen the ticket if you still experience some problems.

datenhahn commented 8 years ago

I also opened a bug for vaadin regarding the can't sort when using label component in header which I found when trying to debug your bug :)

https://dev.vaadin.com/ticket/19620

Fluffysandals commented 8 years ago

Cheers, thanks for the fast support!