Skip to content

Flash Redirect Helpers + ResponseContext#52

Merged
kainovaii merged 1 commit intomainfrom
dev
Mar 19, 2026
Merged

Flash Redirect Helpers + ResponseContext#52
kainovaii merged 1 commit intomainfrom
dev

Conversation

@kainovaii
Copy link
Member

@kainovaii kainovaii commented Mar 19, 2026

Pull Request: Flash Redirect Helpers + ResponseContext

Summary

Adds typed redirect helpers to BaseController (redirectWithSuccess, redirectWithError, etc.) and introduces ResponseContext to eliminate req, res boilerplate in flash redirects.


Changes

1. ResponseContext — ThreadLocal for Response

Added: livecomponents/http/ResponseContext.java

  • Mirrors the existing RequestContext pattern: ThreadLocal<Response> with set(), get(), clear()
  • Enables controllers to access the current response without passing it through the call chain

2. SessionMiddleware — wire ResponseContext

Modified: SessionMiddleware.java

  • ResponseContext.set(res) added alongside RequestContext.set(req) in handle()
  • ResponseContext.clear() added to the static clear() method to prevent memory leaks

3. BaseController — typed flash redirect helpers

Modified: BaseController.java

  • redirectWithFlash() now uses RequestContext.get() / ResponseContext.get() instead of the non-existent Spark.request() / Spark.response()
  • Added redirectWithSuccess(), redirectWithError(), redirectWithWarning(), redirectWithInfo()
  • Cleaned up duplicate imports (spark.Request was imported twice, import static spark.Spark.* was unused)
// Before
setFlash(req, "success", "Kit créé");
res.redirect("/kits");
halt();

// After
redirectWithSuccess("Kit créé", "/kits");

Breaking Changes

redirectWithFlash(Request req, Response res, String type, String message, String location) signature changed to redirectWithFlash(String type, String message, String location). Any existing calls passing req, res must be updated to drop those parameters.

@kainovaii kainovaii merged commit 986286f into main Mar 19, 2026
2 checks passed
@kainovaii kainovaii changed the title Rework redirectFlash methods, create ResponseContext Flash Redirect Helpers + ResponseContext Mar 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant