Over a million developers have joined DZone.

A New CDI Scope in Java EE 8?

The MVC Expert Group is introducing a new CDI custom scope to support redirect. Here's what that means for you...

· Java Zone

Discover how powerful static code analysis and ergonomic design make development not only productive but also an enjoyable experience, brought to you in partnership with JetBrains

At this stage, it is probably safe to say that a new CDI scope will be introduced in Java EE 8 as the MVC Expert Group (JSR 371) is in the process of introducing a new CDI custom scope (@RedirectScoped) to support redirect. 

The idea is simple; an MCV controller can decide to redirect a client to a specific URL, to a specific controller method. A typical example would be that an anonymous user hits a page that required to be logged; the controller will then redirect the user to a login page. To do this, the controller uses HTTP 302 ('moved temporarily') to invite the client to make a new request to a different URL to a different controller.  That second request implies a new (and thus different) request-response cycle. And that's the 'raison-d'être' of this new @RedirectScoped scope, i.e. to allow maintaining some state between the 2 request-response cycles of a redirect. Note that this new scope is for the MVC API only. That new scope is sometime referred as the 'Flash scope.' You can see how both redirect and @RedirectScoped works here.

The great thing about this new scope is that it is just a new CDI custom scope. This is a great example on how the Java EE Platform leverages its foundation to evolve. 

And last but not least, make sure to provide feedback as JSR 371 is in Early Draft period review.

Learn more about Kotlin, a new programming language designed to solve problems that software developers face every day brought to you in partnership with JetBrains.

java,java ee,java ee 8,cdi

Published at DZone with permission of David Delabassee, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}