Seam and EJBs in a Web Project
zpalmer Jun 27, 2008 7:29 PMHello, all. I have a question regarding best practice in terms of three tier design and use of Seam and RichFaces in my project. The project is currently separated out into the usual ejb/web/ear sections and I have an object model in my ejb project which I would like to display to the user. The model is a tree structure which we persist to a database.
In order to display the tree structure to the user, I have created a subclass of org.richfaces.framework.TreeNodeImpl called TaskUITreeNode which mirrors that tree structure by wrapping each node as the data object and then populating child TreeNode objects using the children of the node it wrapped. So I have my own tree structure contained within the TreeNodeImpl extension I have created in order to display it.
I now need to be able to make the tree structure available. The object model root node is available in a bean named ratings
as project
; I need to access that object, wrap it in the TreeNodeImpl subclass, and provide it. So I create the following bean:
@Name("ratingTree") @Scope(SESSION) public class RatingTreeBean { @In private Rating rating; public TaskUITreeNode getRootNode() { return new TaskUITreeNode(rating.getProject()); } }
So far so good. But when I reference the bean from the page like so...
<rich:tree binding="#{ratingTree.rootNode}"/>
I get an exception:
... Caused by: javax.el.PropertyNotFoundException: /project_rating.xhtml @23,48 binding="#{ratingTree.rootNode}": Target Unreachable, identifier 'ratingTree' resolved to null at com.sun.facelets.el.TagValueExpression.setValue(TagValueExpression.java:95) at com.sun.faces.application.ApplicationImpl.createComponent(ApplicationImpl.java:237) ... 68 more
Now, I know why this is: the bean itself is in the web project and not the EJB project. I do this because the bean is not in any way related to application logic; it's not second tier. The RatingTreeBean is entirely related to first-tier logic: the presentation of the tree structure I have created. To put it another way, if I were to create a desktop application using the code from this project, I would expect to use everything from the ejb project and nothing from the web project. As a result, I put the RatingTreeBean (something I would not be able to re-use in the hypothetical desktop version of the app) in the web project where it belongs.
If I move that bean to the EJB project, it seems to work. So my question is this: what do I do to make the bean in the web project visible and usable like it should be? If I can't, what's the rationale?
Thanks!