users@glassfish.java.net

Re: Is it a good idea to implement

From: Jason Lee <jason_at_steeplesoft.com>
Date: Thu, 12 Jun 2008 13:41:06 -0500

On Thu, Jun 12, 2008 at 12:51 PM, <glassfish_at_javadesktop.org> wrote:

> Thanks,Jason. But that comes another question.you said "keep it in a class
> separate from the JSF managed beans that are directly used for controlling
> the view", I like this approach. But how do you manage to get the Entity
> Manager in those plain POJO. I know how to do it in a servlet or
> in a JSF managed bean but not for plain POJO? Thanks.
>

A JSF Managed Bean, when deployed in a Servlet 2.5 app (your web.xml must
use version 2.5) and compliant container, is elgible for injection. You
would, then, simply put the appropriate JPA annotations in your managed
beans and let the container handle the injection when the object is
instantiated.

A very simple classes/packages scheme, then, for what it's worth, might look
like this:

com.foo.myapp.view.OrderBean
com.foo.myapp.service.OrderService
com.foo.myapp.dao.OrderDAO (assuming you want/need a separate DAO)

All of these would be managed by JSF, but the developer would have to be
careful not to use the .service.* and .dao.* beans from the pages. Rather,
the #{dao} bean would be wired into #{service} as a managed property in
faces-config.xml. Likewise, #{service} would be wired into #{orderBean},
which would be the only managed bean to be directly accessed from the view
markup.

Does that make sense?

-- 
Jason Lee, SCJP
Software Architect -- Objectstream, Inc.
Mojarra and Mojarra Scales Dev Team
https://mojarra.dev.java.net
https://scales.dev.java.net
http://blogs.steeplesoft.com