5 Replies Latest reply on Jun 30, 2008 10:53 PM by System Administrator

    Seam and EJBs in a Web Project

    Zachary Palmer Newbie

      Hello, 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:

      public class RatingTreeBean {
           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?


        • 1. Re: Seam and EJBs in a Web Project
          System Administrator Expert

          Your strategy seems logical.  yes, you don't really want that class to be part of your business-logic tier (e.g. does it need transactions, security, web services, etc.?).  and it's not a backing bean or action class for a JSF.

          I believe when Seam initializes after you startup JBoss, it scans the WARs/EARs in the server/default/deploy directory for all classes annotated with @Name.  These classes are then loaded into the appropriate context spaces so that they can be accessed when the Seam app executes.

          example from NumberGuess distro example:

          2008-06-29 09:16:47,206 INFO  [org.jboss.seam.init.Initialization] initializing Seam
          2008-06-29 09:16:47,320 INFO  [org.jboss.seam.Component] Component: org.jboss.seam.core.init, scope: APPLICATION, type: JAVA_BEAN, class: org.jboss.seam.core.Init

          Check your server.log to see if a line like above (for


          ) is output.

          • 2. Re: Seam and EJBs in a Web Project
            Zachary Palmer Newbie


            Thanks for your response.  I have checked the output on the console; the majority of the annotated Seam classes recognized are JBoss Seam classes.  I do see the component registration for the classes in our project, though, and ratingTree is not among them.

            So I guess the question is this: any idea why Seam isn't finding the ratingTree bean in the WAR and loading it?  I know that it's more common for the beans to be in the EJB project and not the WAR itself, but is Seam incapable of reading the beans out of the WAR file?  Or mayhap I have failed to configure something properly?


            • 3. Re: Seam and EJBs in a Web Project
              Tom Kramer Newbie

              There must be a seam.properties file in the war classpath even if it is just empty. Otherwise Seam won't parse your WAR-Classes for Seam Annotations.

              And btw. i don't think that it is less common to put Beans to the WAR-Part of your Application. Where would you put your Managed JSF Beans otherwise?

              • 4. Re: Seam and EJBs in a Web Project
                Zachary Palmer Newbie


                Thank you for your response; the missing seam.properties file you suggested was indeed the problem.  The bean now compiles into the WAR and is visible by Seam just as I wanted.  Huzzah!


                • 5. Re: Seam and EJBs in a Web Project
                  System Administrator Expert

                  I'm assuming you did not use seam-gen to create your WAR project.  The seam.properties file would have been in the resources folder.

                  We always use seam-gen (actually a modified version of seam-gen for our company) and it will eliminate a lot of headache if you do too.

                  Although doing it by hand will force you to learn/understand what all the config files are doing, etc.