Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

A New CDI Scope in Java EE 8?

DZone's Guide to

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
Free Resource

The single app analytics solutions to take your web and mobile apps to the next level.  Try today!  Brought to you in partnership with CA Technologies

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.

CA App Experience Analytics, a whole new level of visibility. Learn more. Brought to you in partnership with CA Technologies.

Topics:
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.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}