Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

changing anotations from JBoss Seam to CDI (JEE6)

We are migrating our App from JBoss Seam to CDI (JEE6), so we are changing some anotations like @In and @Out, there's a lot of information that we have found helpful, but we have some troubles trying to find out how to replace anotations with particular patterns:

For @In anotation

@Name("comprobantes")//context name
...
@In(create=false,value="autenticadoPOJO",required=false)
    private UsuarioPOJO autenticadoPOJO;

We can use @Inject from CDI, but how to set the name of the context variable for this case?.

For the @Out anotation

@Out(scope = ScopeType.SESSION, value = "autenticadoPOJO", required = false)

I have read some blogs and they say that I can use @Produces in CDI, how we can set the scope, before or after adding this anotation?

I appreciate any help or any helpful documentation.

like image 231
William López Avatar asked Apr 11 '12 23:04

William López


2 Answers

I'm afraid there is no such thing like a 1:1 compatibility for @Out.

Technically, @Out in Seam 2 was realized by an interceptor for all method invocations - this turned out to be quite a performance bottleneck.

In CDI, most managed beans are proxied, this makes it technically impossible to implement outjection in the Seam 2 way.

What you can do (well, what you actually have to do) is going through all usages of @Out and replace it individually with some @Producer logic. Have a look at this official example here. In Seam 2, you would have outjected the authenticated user to the session-scope, in CDI a little producer method does (almost) the same.

That should hopefully give you a good start, feel free to ask further questions :)

like image 149
Jan Groth Avatar answered Sep 30 '22 07:09

Jan Groth


http://docs.jboss.org/weld/reference/1.0.0/en-US/html/producermethods.html

8.1. Scope of a producer method

The scope of the producer method defaults to @Dependent, and so it will be called every time the container injects this field or any other field that resolves to the same producer method. Thus, there could be multiple instances of the PaymentStrategy object for each user session.

To change this behavior, we can add a @SessionScoped annotation to the method.

@Produces @Preferred @SessionScoped
public PaymentStrategy getPaymentStrategy() {
   ...
}
like image 24
uaarkoti Avatar answered Sep 30 '22 05:09

uaarkoti