7 Replies Latest reply on Mar 2, 2006 12:32 PM by blue_due

    @Role problem

    blue_due

      I'm working with Seam 1.0 beta 2 and am having some difficulty getting the @Roles annotation to work. It doesn't seem to be binding the component to a context variable or something like that.

      Here is a simple example which I can't get to work:

      The component:

      package uk.foo;
      
      import java.io.Serializable;
      
      import org.jboss.seam.ScopeType;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.annotations.Role;
      
      
      @Name("test")
      @Role(name="foo", scope=ScopeType.SESSION)
      public class TestBean implements Serializable{
      
       /**
       *
       */
       private static final long serialVersionUID = -5547267267271374344L;
      
      
      
       private String foo;
      
      
      
       public TestBean() {}
      
      
      
       public String getFoo() {
       return foo;
       }
      
      
      
       public void setFoo(String foo) {
       this.foo = foo;
       }
      
      
      
      
      }
      





      An action:
      package uk.foo;
      
      import javax.ejb.Stateless;
      
      import org.jboss.seam.ScopeType;
      import org.jboss.seam.annotations.In;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.annotations.Scope;
      
      @Stateless
      @Name("fooaction")
      @Scope(ScopeType.SESSION)
      @Interceptors(SeamInterceptor.class)
      public class FooAction implements Foo {
      
       @In
       private TestBean foo;
      
       public String foo() {
       System.out.println(foo.getFoo());
       return "foo";
      
       }
      
      }
      


      The JSP:
      <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
       pageEncoding="ISO-8859-1"%>
      <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
      <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
      <%@ taglib uri="http://myfaces.apache.org/tomahawk" prefix="t"%>
      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
      <html>
      <head>
      <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
      <title>Test</title>
      </head>
      <body>
       <f:view>
       <h:form>
       <table>
       <tr>
       <td>Foo</td>
       <td><h:inputText value="#{foo.foo}" /></td>
       </tr>
      
       </table>
       <h:commandButton type="submit" value="Foo"
       action="#{fooaction.foo}"/>
       <h:messages />
       </h:form>
       </f:view>
      
      </body>
      </html>
      


      Log from server after pressing the 'Foo' button:
      2006-02-22 22:37:38,364 DEBUG [org.jboss.seam.contexts.Lifecycle] >>> Begin web request
      2006-02-22 22:37:38,376 DEBUG [org.jboss.seam.Component] instantiating Seam component: org.jboss.seam.core.manager
      2006-02-22 22:37:38,376 DEBUG [org.jboss.seam.core.Manager] No stored conversation
      2006-02-22 22:37:38,376 DEBUG [org.jboss.seam.contexts.Contexts] found in application context: org.jboss.seam.core.init
      2006-02-22 22:37:38,377 DEBUG [org.jboss.seam.jsf.SeamPhaseListener] After restore view, conversation context: ConversationContext(4)
      2006-02-22 22:37:38,377 DEBUG [org.jboss.seam.jsf.SeamVariableResolver] resolving name: foo
      2006-02-22 22:37:38,377 DEBUG [org.jboss.seam.Component] seam component not found: foo
      2006-02-22 22:37:38,377 DEBUG [org.jboss.seam.jsf.SeamVariableResolver] could not resolve name
      2006-02-22 22:37:38,380 DEBUG [org.jboss.seam.jsf.SeamPhaseListener] Before saving state
      2006-02-22 22:37:38,380 DEBUG [org.jboss.seam.core.Manager] Discarding conversation state: 4
      2006-02-22 22:37:38,388 DEBUG [org.jboss.seam.contexts.Lifecycle] After render response, destroying contexts
      2006-02-22 22:37:38,388 DEBUG [org.jboss.seam.contexts.Lifecycle] flushing business process context
      2006-02-22 22:37:38,388 DEBUG [org.jboss.seam.contexts.BusinessProcessContext] no process instance to persist business process state
      2006-02-22 22:37:38,388 DEBUG [org.jboss.seam.contexts.Lifecycle] destroying event context
      2006-02-22 22:37:38,388 DEBUG [org.jboss.seam.contexts.Contexts] destroying: org.jboss.seam.core.manager
      2006-02-22 22:37:38,388 DEBUG [org.jboss.seam.contexts.Lifecycle] destroying conversation context
      2006-02-22 22:37:38,388 DEBUG [org.jboss.seam.contexts.Lifecycle] flushing server-side conversation context
      2006-02-22 22:37:38,391 DEBUG [org.jboss.seam.contexts.Lifecycle] <<< End web request
      


      I also get a "Coneversion Error" in my <h:messages /> thingy.

      Apologies for excessive foo-ing .

        • 1. Re: @Role problem
          gavin.king

          What does the startup log say? Does it actually log the component at startup?

          • 2. Re: @Role problem
            blue_due

            Sorry, should have included that in my last post.

            It doesn't log the components. Using the '@Name' name works fine. It's as though the @Role annotation is being ignored. I've checked out the latest cvs version of seam.

            I've had a look through the seam code it looks as though the only class that knows about roles in components is: org.jboss.seam.init.Initialization. It checks for the @Role/@Roles annotations in the compponents contained in the init context variable. When I run my example the init.getComponentClasses returns zero components.

            Later on in Initilization, there are another few lines that add components using a Scanner instance which does not appear to be aware of @Role/@Roles annotaions. My components are picked up here.

            Here is the block of code that contains the only references to the Role annotations that I could find. The body of the for loop does not get run as no component classes are returned. This is taken from org.jboss.seam.init.Initilization, line 165 onwards.

             //TODO: move all this stuff into Init component?
             for ( String className : init.getComponentClasses() )
             {
             try
             {
             Class<Object> componentClass = Reflections.classForName(className);
             addComponent( componentClass, context );
             if ( componentClass.isAnnotationPresent(Role.class) )
             {
            
             Role role = componentClass.getAnnotation(Role.class);
             ScopeType scope = Seam.getComponentRoleScope(componentClass, role);
             addComponent( role.name(), scope, componentClass, context );
             }
             if ( componentClass.isAnnotationPresent(Roles.class) )
             {
             Role[] roles =componentClass.getAnnotation(Roles.class).value();
             for (Role role: roles)
             {
             ScopeType scope = Seam.getComponentRoleScope(componentClass, role);
             addComponent( role.name(), scope, componentClass, context );
             }
             }
             }
             catch (ClassNotFoundException cnfe)
             {
             throw new IllegalArgumentException("Component class not found: " + className, cnfe);
             }
             }
            


            Here is the scanner bit which appears to register components using only the @Name annotation. My component classes get picked up here, but their Role annotations are not looked at. This is taken from org.jboss.seam.init.Initilization, line 220 onwards.

            if (isScannerEnabled)
             {
             for ( Class clazz: new Scanner().getClasses() )
             {
             if ( clazz.isAnnotationPresent(Name.class) )
             {
             addComponent(clazz, context);
             }
             }
             }
            


            I think I'm either doing something wrong which is stopping my components appearing in init.getComponentClasses() or I've found a bug.

            Relavent startup output:

            09:04:38,193 INFO [Scanner] scanning: /C:/Program Files/jboss-4.0.4RC1/server/default/tmp/deploy/tmp25621test.ear-contents/test.jar
            09:04:38,240 INFO [Component] Component: fooaction, scope: SESSION, type: STATELESS_SESSION_BEAN, class: uk.foo.FooAction, JNDI: test/FooAction/local
            09:04:38,271 INFO [Component] Component: test, scope: SESSION, type: JAVA_BEAN, class: uk.foo.TestBean
            09:04:38,286 INFO [Initialization] done initializing Seam
            


            The full log:

            09:04:35,802 INFO [EARDeployer] Init J2EE application: file:/C:/Program Files/jboss-4.0.4RC1/server/default/deploy/test.ear
            09:04:36,755 INFO [Ejb3AnnotationHandler] found EJB3: ejbName=FooAction, class=uk.foo.FooAction, type=STATELESS
            09:04:36,818 FATAL [PersistenceXmlLoader] userDatabase JTA
            09:04:36,833 INFO [Ejb3Deployment] EJB3 deployment time took: 140
            09:04:36,849 INFO [JmxKernelAbstraction] installing MBean: persistence.units:ear=test.ear.ear,jar=test.jar.jar,unitName=userDatabase with dependencies:
            09:04:36,849 INFO [JmxKernelAbstraction] jboss.jca:name=DefaultDS,service=ManagedConnectionFactory
            09:04:36,911 INFO [ConnectionProviderFactory] Initializing connection provider: org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider
            09:04:36,927 INFO [InjectedDataSourceConnectionProvider] Using provided datasource
            09:04:36,927 INFO [SettingsFactory] RDBMS: HSQL Database Engine, version: 1.8.0
            09:04:36,927 INFO [SettingsFactory] JDBC driver: HSQL Database Engine Driver, version: 1.8.0
            09:04:36,927 INFO [Dialect] Using dialect: org.hibernate.dialect.HSQLDialect
            09:04:36,943 INFO [TransactionFactoryFactory] Using default transaction strategy (direct JDBC transactions)
            09:04:36,943 INFO [TransactionManagerLookupFactory] instantiating TransactionManagerLookup: org.hibernate.transaction.JBossTransactionManagerLookup
            09:04:36,943 INFO [TransactionManagerLookupFactory] instantiated TransactionManagerLookup
            09:04:36,943 INFO [SettingsFactory] Automatic flush during beforeCompletion(): enabled
            09:04:36,943 INFO [SettingsFactory] Automatic session close at end of transaction: disabled
            09:04:36,943 INFO [SettingsFactory] JDBC batch size: 15
            09:04:36,943 INFO [SettingsFactory] JDBC batch updates for versioned data: disabled
            09:04:36,943 INFO [SettingsFactory] Scrollable result sets: enabled
            09:04:36,943 INFO [SettingsFactory] JDBC3 getGeneratedKeys(): disabled
            09:04:36,943 INFO [SettingsFactory] Connection release mode: after_statement
            09:04:36,943 INFO [SettingsFactory] Default batch fetch size: 1
            09:04:36,943 INFO [SettingsFactory] Generate SQL with comments: disabled
            09:04:36,943 INFO [SettingsFactory] Order SQL updates by primary key: disabled
            09:04:36,943 INFO [SettingsFactory] Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
            09:04:36,943 INFO [ASTQueryTranslatorFactory] Using ASTQueryTranslatorFactory
            09:04:36,943 INFO [SettingsFactory] Query language substitutions: {}
            09:04:36,943 INFO [SettingsFactory] Second-level cache: enabled
            09:04:36,943 INFO [SettingsFactory] Query cache: disabled
            09:04:36,943 INFO [SettingsFactory] Cache provider: org.hibernate.cache.HashtableCacheProvider
            09:04:36,943 INFO [SettingsFactory] Optimize cache for minimal puts: disabled
            09:04:36,943 INFO [SettingsFactory] Structured second-level cache entries: disabled
            09:04:36,943 INFO [SettingsFactory] Statistics: disabled
            09:04:36,943 INFO [SettingsFactory] Deleted entity synthetic identifier rollback: disabled
            09:04:36,943 INFO [SettingsFactory] Default entity-mode: pojo
            09:04:36,943 INFO [SessionFactoryImpl] building session factory
            09:04:36,943 INFO [SessionFactoryObjectFactory] Not binding factory to JNDI, no JNDI name configured
            09:04:36,943 INFO [SchemaExport] Running hbm2ddl schema export
            09:04:36,943 INFO [SchemaExport] exporting generated schema to database
            09:04:36,958 INFO [SchemaExport] schema export complete
            09:04:36,958 INFO [NamingHelper] JNDI InitialContext properties:{java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory, java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces}
            09:04:36,974 INFO [JmxKernelAbstraction] installing MBean: jboss.j2ee:service=EJB3,ear=test.ear,jar=test.jar,name=FooAction with dependencies:
            09:04:37,224 INFO [EJB3Deployer] Deployed: file:/C:/Program Files/jboss-4.0.4RC1/server/default/tmp/deploy/tmp25621test.ear-contents/test.jar
            09:04:37,224 INFO [TomcatDeployer] deploy, ctxPath=/test, warUrl=.../tmp/deploy/tmp25621test.ear-contents/test-exp.war/
            09:04:37,536 INFO [ServletContextListener] Welcome to Seam 1.0 beta 2
            09:04:37,552 INFO [Initialization] reading properties from: /seam.properties
            09:04:37,568 INFO [Initialization] initializing Seam
            09:04:37,646 INFO [Component] Component: org.jboss.seam.core.init, scope: APPLICATION, type: JAVA_BEAN, class: org.jboss.seam.core.Init
            09:04:37,693 INFO [Component] Component: org.jboss.seam.core.pages, scope: APPLICATION, type: JAVA_BEAN, class: org.jboss.seam.core.Pages
            09:04:37,724 INFO [Component] Component: org.jboss.seam.core.manager, scope: EVENT, type: JAVA_BEAN, class: org.jboss.seam.core.Manager
            09:04:37,771 INFO [Component] Component: switcher, scope: PAGE, type: JAVA_BEAN, class: org.jboss.seam.core.Switcher
            09:04:37,818 INFO [Component] Component: conversation, scope: CONVERSATION, type: JAVA_BEAN, class: org.jboss.seam.core.Conversation
            09:04:37,865 INFO [Component] Component: conversationList, scope: PAGE, type: JAVA_BEAN, class: org.jboss.seam.core.ConversationList
            09:04:37,896 INFO [Component] Component: conversationStack, scope: PAGE, type: JAVA_BEAN, class: org.jboss.seam.core.ConversationStack
            09:04:37,911 INFO [Component] Component: facesContext, scope: APPLICATION, type: JAVA_BEAN, class: org.jboss.seam.core.FacesContext
            09:04:37,927 INFO [Component] Component: eventContext, scope: APPLICATION, type: JAVA_BEAN, class: org.jboss.seam.core.EventContext
            09:04:37,943 INFO [Component] Component: sessionContext, scope: APPLICATION, type: JAVA_BEAN, class: org.jboss.seam.core.SessionContext
            09:04:37,958 INFO [Component] Component: statelessContext, scope: APPLICATION, type: JAVA_BEAN, class: org.jboss.seam.core.StatelessContext
            09:04:37,974 INFO [Component] Component: applicationContext, scope: APPLICATION, type: JAVA_BEAN, class: org.jboss.seam.core.ApplicationContext
            09:04:37,990 INFO [Component] Component: conversationContext, scope: APPLICATION, type: JAVA_BEAN, class: org.jboss.seam.core.ConversationContext
            09:04:38,005 INFO [Component] Component: businessProcessContext, scope: APPLICATION, type: JAVA_BEAN, class: org.jboss.seam.core.BusinessProcessContext
            09:04:38,036 INFO [Component] Component: resourceBundle, scope: APPLICATION, type: JAVA_BEAN, class: org.jboss.seam.core.ResourceBundle
            09:04:38,052 INFO [Component] Component: org.jboss.seam.debug.introspector, scope: EVENT, type: JAVA_BEAN, class: org.jboss.seam.debug.Introspector
            09:04:38,146 INFO [ResourceBundle] resource bundle missing: messages
            09:04:38,161 INFO [Component] Component: org.jboss.seam.debug.contexts, scope: APPLICATION, type: JAVA_BEAN, class: org.jboss.seam.debug.Contexts
            09:04:38,193 INFO [Scanner] scanning: /C:/Program Files/jboss-4.0.4RC1/server/default/tmp/deploy/tmp25621test.ear-contents/test.jar
            09:04:38,240 INFO [Component] Component: fooaction, scope: SESSION, type: STATELESS_SESSION_BEAN, class: uk.foo.FooAction, JNDI: test/FooAction/local
            09:04:38,271 INFO [Component] Component: test, scope: SESSION, type: JAVA_BEAN, class: uk.foo.TestBean
            09:04:38,286 INFO [Initialization] done initializing Seam
            09:04:38,286 INFO [FacesConfigurator] Reading standard config org/apache/myfaces/resource/standard-faces-config.xml
            09:04:38,599 INFO [FacesConfigurator] Reading config jar:file:/C:/Program Files/jboss-4.0.4RC1/server/default/tmp/deploy/tmp25569tomahawk.jar!/META-INF/faces-config.xml
            09:04:38,708 ERROR [LocaleUtils] Locale name null or empty, ignoring
            09:04:39,083 INFO [StartupServletContextListener] ServletContext 'C:\Program Files\jboss-4.0.4RC1\server\default\.\tmp\deploy\tmp25621test.ear-contents\test-exp.war\' initialized.
            09:04:39,193 INFO [EARDeployer] Started J2EE application: file:/C:/Program Files/jboss-4.0.4RC1/server/default/deploy/test.ear
            
            




            • 3. Re: @Role problem
              gavin.king

              Are you trying to use a class with a @Role annotation, but no @Name annotation?

              (That is not what your original code example showed.)

              Currently, Seam does not support components with no "default role".

              • 4. Re: @Role problem
                blue_due

                I'm using both @Name and @Role as in the original example.

                I think I may have given you the wrong impression when I said:


                Using the '@Name' name works fine.


                I meant that I tried using the default name, i.e. I used 'test' to reference the component in the FooAction and JSP just to make sure that the component was working under the default name.





                • 5. Re: @Role problem
                  gavin.king

                  Oh, you are right. It is such a stupid bug. It only detects the @Role annotation when the component is listed on org.jboss.seam.core.init.componentClasses.


                  I am embarrassed.

                  • 6. Re: @Role problem
                    gavin.king

                    Fixed in CVS.

                    • 7. Re: @Role problem
                      blue_due

                      It works :) Cheers.

                      Keep up the good work!