users@javaee-spec.java.net

[javaee-spec users] Managed bean alignment...

From: <hantsy_at_live.cn>
Date: Wed, 12 Sep 2012 08:16:28 +0000 (GMT)

I noticed there is a topic in the expert mail list,

http://java.net/projects/javaee-spec/lists/jsr342-experts/archive/2012-
03/message/74

As an end developer, I only want to express my idea here.

Currently I dislike CDI treat all classes(which has a constructor with
no arguments) as CDI managed bean, I know Jboss Solder provides a @Veto
to resolve this issue.

I think the matrix 2 is clear. I like the two classes solution.

1. the first level, the bean is injectable, has own scope. such EJB,
basic Pojo(annotated with @ManagedBean), @Named etc.

And other bean such as EJB can improve the lifecyle support
transaction, security etc.

Compare to spring framework, it provides @Component, and @Controller,
@Service etc. but the later are refined from the @Component.
Why the @Named, @EJB can not be refined to use @ManagedBean(JEE)?

...
@ManagedBean
.....
interface @Named{
}

...
@ManagedBean
.....
interface @Stateful{
}

2. such as entity listener, faces converter, faces validator, bean
validator, servlet & servlet listener, filter, etc, can inject other
beans.

For example, it should allow us inject EmtityManager in faces
conventer.

But it can NOT be injected in other bean, and can NOT be defined in its
own scope.

In fact, as an end developer I only want to simplify programming, but
do not want to change their lifecyle.

But besides the CDI interceptors, decorators, I think it should be
optional, developer can select if use CDI to manage it.

For the 2, is there a better solution to make it managed? Spring
provides another @Configurable. In JEE 7, the jee7 expert group can
consider a similar solution, for example, provides a @Managed
annotation to improve the lifecyle.

@WebServlet
@Managed
class MyServlet extends HttpServlet{ //you can use @Inject now, }

if it is not annotated with @Managed...it is no relation to CDI, only a
generic servlet.

@WebServlet
class MyServlet extends HttpServlet{ //_at_Inject is NOT supported, }

This maybe force the different spec providers leave some space for the
CDI hooks in their lifecycle.

In summary, I hope all JEE specs looks smooth and seamless to
developers.

Additionally, the @Entity, I can use @PostLoad, etc. I think it is can
also be managed when JPA process the jpa lifecyle, sush as persist,
merge etc.

@Entity
@Managed
class MyEntity{

......
@Inject Entitymanager em;

@Inject @Loggedin User currentUser;

......
@Prepersist
public void prepersist(){
setCreatedBy(currentUser);
setCreatedOn(new Date());
}

}