solikang
solikang

Reputation: 53

onClick/onSelected Event of a button in a GWT CellList

I have a GWT CellList. Each Cell has one image, two label, and one button.

Whenever user click a Cell, onSelected event occures.

I want to fire onClick event if user click on a button, onSelected if click other area(not inside button).

Is it possible to do that?

Upvotes: 1

Views: 1222

Answers (2)

Paul
Paul

Reputation: 11

The easiest way is to override onBrowserEvent(...) method of AbstractCell<C>. Here is how i implemented it to deal with click events on a <a/> element:

@Override
public void onBrowserEvent(Context context, Element parent, BIBonusDto value, NativeEvent event,
        ValueUpdater<BIBonusDto> valueUpdater) {
    super.onBrowserEvent(context, parent, value, event, valueUpdater);
    if ("click".equals(event.getType())) {
        EventTarget eventTarget = event.getEventTarget();
        if (!Element.is(eventTarget)) {
            return;
        }
        if (parent.getElementsByTagName("a").getItem(0).isOrHasChild(Element.as(eventTarget))) {
            if (valueUpdater != null)
                valueUpdater.update(value);
        }
    }
}

the cell template looks like this:

<div id='info' class='campaign' style='cursor:default;'>
  <div id='claim-inner2'>
    <a id='claim-inner1' style='cursor:pointer;'>
      <div id='claim-inner' title='Claim Points Now'></div>
    </a>
  </div>
</div>

We have to check if the event is of the right type and if it's an element, then we can check if it's the right one and delegate the action to a value updater callback.

Upvotes: 1

vbjain
vbjain

Reputation: 557

I think you want something like this, http://gwt.google.com/samples/Showcase/Showcase.html#!CwCellSampler

You can either have ActionCell or ButtonCell.

Let me know if this serve your purpose or not.

Upvotes: 0

Related Questions