ArcBees / GWTP

A complete model-view-presenter framework to simplify your next GWT project.
Other
335 stars 132 forks source link

NestedSlot ClassCastException #729

Closed danielkaneider closed 9 years ago

danielkaneider commented 9 years ago

The PresenterWidget.clearSlot method is very type safe, but this is not yet valid for setInSlot. Mainly, when you try doing

setInSlot(A_NESTED_SLOT, null)

this results in an exception. The main problem IMHO is, that NestedSlot should implement IsRemovable, otherwise the return true in it's isRemovableMethod doesn't make much sense.

rdwallis commented 9 years ago

This problem couldn't be solved while maintaining backward compatibility.

It may work to cast the null:

setInSlot(A_NESTED_SLOT, (NestedSlot) null) but otherwise it's not calling the type safe method I think.

So use clearSlot for now and then we can fix this when we drop support for the old slots.

danielkaneider commented 9 years ago

The problem arises when firing a RevealContentEvent with null. I don't think the problem is the wrong mapping of the setInSlot method, but rather what is happening inside the new setInSlot method.

Adding RemovableSlot to NestedSlot should solve the problem, if that is the intended behaviour.

rdwallis commented 9 years ago

I don't have the gwtp code in front of me so this may be wrong and I can't do a PR

but at: https://github.com/ArcBees/GWTP/blob/master/gwtp-core/gwtp-mvp-client/src/main/java/com/gwtplatform/mvp/client/proxy/RevealContentHandler.java#L67

Replace line 67 & 68 with:

if (revealContentEvent.getContent() == null) {
   presenter.clearSlot((NestedSlot) revealContentEvent.getAssociatedType());
} else {
  presenter.setInSlot((NestedSlot) revealContentEvent.getAssociatedType(),
                                    revealContentEvent.getContent());
}

And it should solve the problem.