What is the difference between flash(a, b) and flash().put(a, b) in PlayFramework?

72 views Asked by At

In terms of a implementation of flash message in Play, I saw two ways. Those are flash(flashKey, flashMessage) and flash().put(flashKey, flashMessage) where both flashKey and flashMessage are String. What exactly is the difference?

1

There are 1 answers

1
tgk On

flash().put(key, message) is the Flash class interface for adding the given value the flash scope

flash(key, message) is the RequestBuilder interface for updating the flash session. Under the hood it does exactly the same as new HashMap<>(flash()).put(key, message) (source here) but it looks like it does the additional step of updating the request cookies

I believe you should use flash(key, message) to ensure that any updates to the flash are persisted.