GiftCard demo buggy

Hello Team,

First thanks for this nice framework, and all the tutorials and demos around.

I was playing a little bit with the GiftCard demo, and found possibly a bug.

When you redeem a giftcard, the FetchCardSummariesQuery subscription query is correctly intercepting the redeem event, and fires a Vaadin DataRefreshEvent as per the below code

             fetchQueryResult.updates().subscribe(
                    cardSummary -> {
                        logger.debug("processing query update for {}: {}", fetchCardSummariesQuery, cardSummary);
                        /* This is a Vaadin-specific call to update the UI as a result of data changes. */
                        fireEvent(new DataChangeEvent.DataRefreshEvent<>(this, cardSummary));
                    });

However, as you don’t override properly the equals and hashCode methods in CardSummary data class,
Vaadin will not update/refresh the entity during the push (data class relies on the fields provided in the primary constructor to build the equals and hashCode methods, so keeps the remainingValue in the equals calculation which is wrong)

See com.vaadin.data.provider.DataCommunicator#refresh

     if (activeData.containsKey(id)) {   // this will never be the case with your code
                // Item is currently available at the client-side
                if (updatedData.isEmpty()) {
                    markAsDirty();
                }
                updatedData.add(activeData.get(id));
            }

In your case, the GUI is updated because you have left a pollIntervall in the GiftCardGui. I think you should remove this piece of code, which is a little bit misleading when using reactive/subscription query code.

Regards

Hi Cyrillus,
thank you for your post. I am glad you like the Framework. Yes, the GiftCard app could use some love I am afraid. The Vaadin version is also quite old. We have spent a lot of time on a totally new demo app based on a hotel use-case, but it is a lot bigger. Still, the gift card repo is public, so if you could make a PR out of your recommendations I would be very much obliged. :wink:

Cheers,
Bert Laverman

Just to add to @Bert_Laverman’s answer, you can find the hotel-demo here.

Hello Bert, Lucas,

I have pushed the PR

When i will have time i will upgrade your demo with Vaadin 14.
It’s pretty quick to do

Cheers

3 Likes