10 Replies Latest reply on Jan 26, 2006 7:44 AM by Gavin King

    Seam Newbie Problem

    Cody Lerum Newbie

      So I have created a small application just get a basic understanding of SEAM. I have the app deploying without errors.

      17:21:14,832 INFO [EARDeployer] Init J2EE application: file:/C:/jboss-4.0.3SP1/server/default/deploy/phone-log.ear
      17:21:14,926 INFO [JaccHelper] Initialising JACC Context for deployment: phone-log.ejb3
      17:21:14,972 INFO [Ejb3AnnotationHandler] found EJB3: ejbName=org.transaria.noc.UserUtilsAction, class=org.transaria.noc.UserUtilsAction, type=STATELESS
      17:21:15,613 INFO [JaccHelper] org.transaria.noc.UserUtilsAction has no @SecurityDomain - skipping JACC configuration
      17:21:15,754 INFO [Ejb3Deployment] Found persistence.xml file in EJB3 jar
      17:21:15,785 INFO [Ejb3Configuration] found EJB3 Entity bean: org.transaria.noc.User
      17:21:15,816 INFO [Configuration] processing extends queue
      17:21:15,832 INFO [Configuration] processing collection mappings
      17:21:15,832 INFO [Configuration] processing association property references
      17:21:15,832 INFO [Configuration] processing foreign key constraints
      17:21:15,847 INFO [Configuration] processing extends queue
      17:21:15,847 INFO [Configuration] processing collection mappings
      17:21:15,847 INFO [Configuration] processing association property references
      17:21:15,847 INFO [Configuration] processing foreign key constraints
      17:21:15,863 INFO [ConnectionProviderFactory] Initializing connection provider: org.hibernate.ejb.InjectedDataSourceConnectionProvider
      17:21:15,894 INFO [InjectedDataSourceConnectionProvider] Using provided datasource
      17:21:15,894 INFO [SettingsFactory] RDBMS: HSQL Database Engine, version: 1.8.0
      17:21:15,894 INFO [SettingsFactory] JDBC driver: HSQL Database Engine Driver, version: 1.8.0
      17:21:15,894 INFO [Dialect] Using dialect: org.hibernate.dialect.HSQLDialect
      17:21:15,894 INFO [TransactionFactoryFactory] Using default transaction strategy (direct JDBC transactions)
      17:21:15,894 INFO [TransactionManagerLookupFactory] instantiating TransactionManagerLookup: org.hibernate.transaction.JBossTransactionManagerLookup
      17:21:15,910 INFO [TransactionManagerLookupFactory] instantiated TransactionManagerLookup
      17:21:15,910 INFO [SettingsFactory] Automatic flush during beforeCompletion(): disabled
      17:21:15,910 INFO [SettingsFactory] Automatic session close at end of transaction: disabled
      17:21:15,910 INFO [SettingsFactory] JDBC batch size: 15
      17:21:15,910 INFO [SettingsFactory] JDBC batch updates for versioned data: disabled
      17:21:15,910 INFO [SettingsFactory] Scrollable result sets: enabled
      17:21:15,910 INFO [SettingsFactory] JDBC3 getGeneratedKeys(): disabled
      17:21:15,910 INFO [SettingsFactory] Connection release mode: after_statement
      17:21:15,910 INFO [SettingsFactory] Default batch fetch size: 1
      17:21:15,910 INFO [SettingsFactory] Generate SQL with comments: disabled
      17:21:15,910 INFO [SettingsFactory] Order SQL updates by primary key: disabled
      17:21:15,910 INFO [SettingsFactory] Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
      17:21:15,910 INFO [ASTQueryTranslatorFactory] Using ASTQueryTranslatorFactory
      17:21:15,910 INFO [SettingsFactory] Query language substitutions: {}
      17:21:15,910 INFO [SettingsFactory] Second-level cache: enabled
      17:21:15,910 INFO [SettingsFactory] Query cache: disabled
      17:21:15,910 INFO [SettingsFactory] Cache provider: org.hibernate.cache.HashtableCacheProvider
      17:21:15,910 INFO [SettingsFactory] Optimize cache for minimal puts: disabled
      17:21:15,910 INFO [SettingsFactory] Structured second-level cache entries: disabled
      17:21:15,910 INFO [SettingsFactory] Statistics: disabled
      17:21:15,910 INFO [SettingsFactory] Deleted entity synthetic identifier rollback: enabled
      17:21:15,910 INFO [SettingsFactory] Default entity-mode: POJO
      17:21:15,926 INFO [SessionFactoryImpl] building session factory
      17:21:16,144 INFO [SessionFactoryObjectFactory] Not binding factory to JNDI, no JNDI name configured
      17:21:16,144 INFO [Configuration] processing extends queue
      17:21:16,144 INFO [Configuration] processing collection mappings
      17:21:16,144 INFO [Configuration] processing association property references
      17:21:16,160 INFO [Configuration] processing foreign key constraints
      17:21:16,160 INFO [Configuration] processing extends queue
      17:21:16,160 INFO [Configuration] processing collection mappings
      17:21:16,160 INFO [Configuration] processing association property references
      17:21:16,160 INFO [Configuration] processing foreign key constraints
      17:21:16,160 INFO [SchemaExport] Running hbm2ddl schema export
      17:21:16,160 INFO [SchemaExport] exporting generated schema to database
      17:21:16,176 INFO [SchemaExport] schema export complete
      17:21:16,176 INFO [Configuration] processing extends queue
      17:21:16,176 INFO [Configuration] processing collection mappings
      17:21:16,176 INFO [Configuration] processing association property references
      17:21:16,176 INFO [Configuration] processing foreign key constraints
      17:21:16,176 INFO [Configuration] processing extends queue
      17:21:16,176 INFO [Configuration] processing collection mappings
      17:21:16,176 INFO [Configuration] processing association property references
      17:21:16,176 INFO [Configuration] processing foreign key constraints
      17:21:16,176 INFO [NamingHelper] JNDI InitialContext properties:{java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory, java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces}
      17:21:16,176 INFO [SessionFactoryImpl] Checking 0 named queries
      17:21:16,191 INFO [Ejb3Deployment] Create EntityManager with JNDI name: phonelogDatabase
      17:21:16,191 INFO [JaccHelper] JACC Policy Configuration for deployment has been put in service
      17:21:16,191 INFO [Ejb3Deployment] EJB3 deployment time took: 1265
      17:21:17,176 INFO [ProxyDeployer] no declared remote bindings for : org.transaria.noc.UserUtilsAction
      17:21:17,254 INFO [EJB3Deployer] Deployed: file:/C:/jboss-4.0.3SP1/server/default/tmp/deploy/tmp42152phone-log.ear-contents/phone-log.ejb3
      17:21:17,269 INFO [TomcatDeployer] deploy, ctxPath=/phone-log, warUrl=.../tmp/deploy/tmp42152phone-log.ear-contents/phone-log-exp.war/
      17:21:17,488 INFO [ServletContextListener] Welcome to Seam 1.0 beta 1
      17:21:17,488 INFO [Seam] initializing Seam
      17:21:17,488 INFO [Component] Component: org.jboss.seam.core.init, scope: APPLICATION, type: JAVA_BEAN, class: org.jboss.seam.core.Init
      17:21:17,504 INFO [Component] Component: org.jboss.seam.core.manager, scope: EVENT, type: JAVA_BEAN, class: org.jboss.seam.core.Manager
      17:21:17,566 INFO [Component] Component: facesContext, scope: APPLICATION, type: JAVA_BEAN, class: org.jboss.seam.core.FacesContext
      17:21:17,597 INFO [Component] Component: eventContext, scope: APPLICATION, type: JAVA_BEAN, class: org.jboss.seam.core.EventContext
      17:21:17,613 INFO [Component] Component: sessionContext, scope: APPLICATION, type: JAVA_BEAN, class: org.jboss.seam.core.SessionContext
      17:21:17,629 INFO [Component] Component: statelessContext, scope: APPLICATION, type: JAVA_BEAN, class: org.jboss.seam.core.StatelessContext
      17:21:17,660 INFO [Component] Component: conversationContext, scope: APPLICATION, type: JAVA_BEAN, class: org.jboss.seam.core.ConversationContext
      17:21:17,707 INFO [Component] Component: applicationContext, scope: APPLICATION, type: JAVA_BEAN, class: org.jboss.seam.core.ApplicationContext
      17:21:17,738 INFO [Component] Component: businessProcessContext, scope: APPLICATION, type: JAVA_BEAN, class: org.jboss.seam.core.BusinessProcessContext
      17:21:17,754 INFO [Scanner] scanning: /C:/jboss-4.0.3SP1/server/default/tmp/deploy/tmp42152phone-log.ear
      17:21:17,754 INFO [Scanner] scanning: /C:/jboss-4.0.3SP1/server/default/tmp/deploy/tmp42152phone-log.ear-contents/phone-log.ejb3
      17:21:17,769 INFO [Scanner] scanning: C:\jboss-4.0.3SP1\server\default\tmp\deploy\tmp42152phone-log.ear-contents\phone-log-exp.war
      17:21:17,769 INFO [Component] Component: userutils, scope: STATELESS, type: STATELESS_SESSION_BEAN, class: org.transaria.noc.UserUtilsAction
      17:21:17,801 INFO [Component] Component: user, scope: CONVERSATION, type: ENTITY_BEAN, class: org.transaria.noc.User
      17:21:17,816 INFO [Seam] done initializing Seam
      17:21:17,816 INFO [FacesConfigurator] Reading standard config org/apache/myfaces/resource/standard-faces-config.xml
      17:21:17,972 INFO [FacesConfigurator] Reading config /WEB-INF/faces-config.xml
      17:21:18,207 INFO [StartupServletContextListener] ServletContext 'C:\jboss-4.0.3SP1\server\default\.\tmp\deploy\tmp42152phone-log.ear-contents\phone-log-exp.war\' initialized.
      17:21:18,332 INFO [EARDeployer] Started J2EE application: file:/C:/jboss-4.0.3SP1/server/default/deploy/phone-log.ear


      But, it is failing when I run the JSP

      17:24:24,365 ERROR [[jsp]] Servlet.service() for servlet jsp threw exception
      java.lang.NullPointerException
       at javax.faces.webapp.UIComponentTag.setupResponseWriter(UIComponentTag.java:646)
       at javax.faces.webapp.UIComponentTag.doStartTag(UIComponentTag.java:254)
       at org.apache.myfaces.taglib.core.ViewTag.doStartTag(ViewTag.java:90)
       at org.apache.jsp.usercreate_jsp._jspx_meth_f_view_0(org.apache.jsp.usercreate_jsp:100)
       at org.apache.jsp.usercreate_jsp._jspService(org.apache.jsp.usercreate_jsp:75)
       at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
       at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
       at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
       at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
       at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
       at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
       at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:81)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
       at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
       at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
       at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:39)
       at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:159)
       at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:59)
       at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
       at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
       at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
       at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
       at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
       at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
       at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
       at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
       at java.lang.Thread.run(Thread.java:595)
      


      This must be something simple as by code couldn't be much more basic.
      usercreate.jsp
      <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
      <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
      <html>
       <head>
       <title>Create New User</title>
       </head>
       <body>
       <f:view>
       <h:form>
       <table border="0">
       <tr>
       <td>Username</td>
       <td><h:inputText value="#{user.username}"/></td>
       </tr>
       <tr>
       <td>First Name</td>
       <td><h:inputText value="#{user.first}"/></td>
       </tr>
       <tr>
       <td>Last Name</td>
       <td><h:inputText value="#{user.last}"/></td>
       </tr>
       <tr>
       <td>Password</td>
       <td><h:inputSecret value="#{user.password}"/></td>
       </tr>
       </table>
       <h:messages/>
       <h:commandButton type="submit" value="Register" action="#{userutils.createUser}"/>
       </h:form>
       </f:view>
       </body>
      </html>
      


      web.xml
      <?xml version="1.0" encoding="UTF-8"?>
      <web-app version="2.4"
       xmlns="http://java.sun.com/xml/ns/j2ee"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
       http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
      
      
       <!-- Seam -->
      
       <listener>
       <listener-class>org.jboss.seam.servlet.SeamListener</listener-class>
       </listener>
      
       <!-- MyFaces -->
      
       <listener>
       <listener-class>
       org.apache.myfaces.webapp.StartupServletContextListener
       </listener-class>
       </listener>
      
       <context-param>
       <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
       <param-value>client</param-value>
       </context-param>
      
       <servlet>
       <servlet-name>Faces Servlet</servlet-name>
       <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
       <load-on-startup>1</load-on-startup>
       </servlet>
      
       <!-- Faces Servlet Mapping -->
       <servlet-mapping>
       <servlet-name>Faces Servlet</servlet-name>
       <url-pattern>/*</url-pattern>
       </servlet-mapping>
      
      </web-app>
      


      faces-config.xml
      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE faces-config
      PUBLIC "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.0//EN"
       "http://java.sun.com/dtd/web-facesconfig_1_0.dtd">
      <faces-config>
      
       <navigation-rule>
       <navigation-case>
       <from-outcome>created</from-outcome>
       <to-view-id>/usercreated.jsp</to-view-id>
       </navigation-case>
       </navigation-rule>
      
       <!-- Same for all Seam applications -->
      
       <application>
       <variable-resolver>org.jboss.seam.jsf.SeamVariableResolver</variable-resolver>
       </application>
      
       <lifecycle>
       <phase-listener>org.jboss.seam.jsf.SeamPhaseListener</phase-listener>
       </lifecycle>
      
      </faces-config>
      


      Can someone point me in the right direction? I feel like I'm getting close to having an understanding, but must be missing something pretty basic.



        • 1. Re: Seam Newbie Problem
          js8523 Novice

          Is there anything that might help in the server.log.

          From the information given it should work but the error given doesn't help to much in pointing out the problem area.

          Please if you can post more error stacks, etc.

          James

          • 2. Re: Seam Newbie Problem
            Gavin King Master

            It looks like you are hitting the JSP directly, instead of hitting the faces servlet. (Yes, this is the extremely inelegant way that JSP craps out when that happens.)

            I'm not sure if your faces servlet mapping is a good one. Try mapping it to *.jsf or *.seam or whatever, like in the example apps.

            • 3. Re: Seam Newbie Problem
              Cody Lerum Newbie

              Thanks guys I was able to make some forward progress based on your suggestions. Turns out I was looking at examples from the CVS and using the beta1 code (so I could use 4.0.3SP1). Seems (no pun intended) that it's a rather confusing time right now to start with beta2 about to go out, but only working with 4.0.4 currently.

              Anyway I got my page to load up. New road block.

              0:22:23,020 INFO [EARDeployer] Started J2EE application: file:/C:/jboss-4.0.3SP1/server/default/deploy/phone-log.ear
              10:22:35,426 WARN [VariableResolverImpl] Variable 'user' could not be resolved.
              10:22:35,426 WARN [VariableResolverImpl] Variable 'user' could not be resolved.
              10:22:35,426 WARN [VariableResolverImpl] Variable 'user' could not be resolved.
              10:22:35,473 INFO [MyfacesConfig] No context init parameter 'org.apache.myfaces.PRETTY_HTML' found, using default value true
              10:22:35,473 INFO [MyfacesConfig] No context init parameter 'org.apache.myfaces.ALLOW_JAVASCRIPT' found, using default value true
              10:22:35,473 INFO [MyfacesConfig] No context init parameter 'org.apache.myfaces.DETECT_JAVASCRIPT' found, using default value false
              10:22:35,473 INFO [MyfacesConfig] No context init parameter 'org.apache.myfaces.AUTO_SCROLL' found, using default value false
              10:22:54,833 WARN [VariableResolverImpl] Variable 'user' could not be resolved.
              10:22:54,849 WARN [VariableResolverImpl] Variable 'user' could not be resolved.
              10:22:54,849 WARN [VariableResolverImpl] Variable 'user' could not be resolved.
              10:22:54,849 WARN [VariableResolverImpl] Variable 'user' could not be resolved.
              10:22:54,849 WARN [VariableResolverImpl] Variable 'user' could not be resolved.
              10:22:54,849 WARN [VariableResolverImpl] Variable 'user' could not be resolved.
              10:22:54,849 WARN [VariableResolverImpl] Variable 'user' could not be resolved.
              10:22:54,849 WARN [VariableResolverImpl] Variable 'user' could not be resolved.
              10:22:54,849 WARN [VariableResolverImpl] Variable 'user' could not be resolved.
              10:22:54,849 WARN [VariableResolverImpl] Variable 'user' could not be resolved.
              10:22:54,849 WARN [VariableResolverImpl] Variable 'user' could not be resolved.
              10:22:54,849 WARN [VariableResolverImpl] Variable 'user' could not be resolved.
              10:22:54,942 WARN [VariableResolverImpl] Variable 'userutils' could not be resolved.
              10:22:54,958 WARN [VariableResolverImpl] Variable 'user' could not be resolved.
              
              


              Thats what the console dumps.

              web.xml

              <?xml version="1.0" encoding="UTF-8"?>
              <web-app version="2.4"
               xmlns="http://java.sun.com/xml/ns/j2ee"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
              
               <!-- Seam -->
              
               <listener>
               <listener-class>org.jboss.seam.servlet.SeamListener</listener-class>
               </listener>
              
               <!-- 120 second conversation timeout -->
               <context-param>
               <param-name>org.jboss.seam.core.manager.conversationTimeout</param-name>
               <param-value>120000</param-value>
               </context-param>
              
               <!-- TODO: Not working yet unless you disable repository scoped classloading by deleting jboss-app.xml -->
               <!-- context-param>
               <param-name>org.jboss.seam.core.init.clientSideConversations</param-name>
               <param-value>true</param-value>
               </context-param-->
              
               <!-- MyFaces -->
              
               <listener>
               <listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>
               </listener>
              
               <context-param>
               <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
               <param-value>client</param-value>
               </context-param>
              
               <context-param>
               <param-name>facelets.DEVELOPMENT</param-name>
               <param-value>true</param-value>
               </context-param>
              
               <context-param>
               <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
               <param-value>.jsp</param-value>
               </context-param>
              
               <servlet>
               <servlet-name>Faces Servlet</servlet-name>
               <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
               <load-on-startup>1</load-on-startup>
               </servlet>
              
               <!-- Faces Servlet Mapping -->
              
               <servlet-mapping>
               <servlet-name>Faces Servlet</servlet-name>
               <url-pattern>*.seam</url-pattern>
               </servlet-mapping>
              
              
              </web-app>
              


              UserUtilsAction.java

              package org.transaria.noc;
              
              import javax.ejb.Local;
              
              @Local
              
              public interface UserUtils {
              
               public String createUser();
              
               }
              


              UserUtilsAction.java

              package org.transaria.noc;
              
              import static org.jboss.seam.ScopeType.EVENT;
              
              import java.util.List;
              import javax.ejb.Interceptor;
              import javax.ejb.Stateless;
              import javax.persistence.EntityManager;
              import javax.persistence.PersistenceContext;
              import org.hibernate.validator.Valid;
              import org.jboss.seam.annotations.IfInvalid;
              import org.jboss.seam.annotations.In;
              import org.jboss.seam.annotations.Name;
              import org.jboss.seam.annotations.Outcome;
              import org.jboss.seam.annotations.Scope;
              
              import javax.faces.application.FacesMessage;
              import javax.faces.context.FacesContext;
              import org.jboss.seam.ejb.SeamInterceptor;
              
              @Stateless
              @Scope(EVENT)
              @Name("userutils")
              @Interceptor(SeamInterceptor.class)
              public class UserUtilsAction implements UserUtils {
              
               @In @Valid
               private User user;
              
               @PersistenceContext
               private EntityManager em;
              
               @In
               private FacesContext facesContext;
              
               @IfInvalid(outcome=Outcome.REDISPLAY)
               public String createUser() {
               List existing = em.createQuery("select username from User where username=:username")
               .setParameter("username", user.getUsername())
               .getResultList();
              
               if (existing.size()==0)
               {
               em.persist(user);
               return "created";
               }
               else
               {
               facesContext.addMessage(null, new FacesMessage("username already exists"));
               return null;
               }
               }
              
              }
              


              User.java

              
              package org.transaria.noc;
              
              import static javax.persistence.GeneratorType.AUTO;
              import static org.jboss.seam.ScopeType.SESSION;
              
              import java.io.Serializable;
              import java.util.Date;
              import javax.persistence.Entity;
              import javax.persistence.Id;
              import javax.persistence.Table;
              import org.hibernate.validator.NotNull;
              import org.jboss.seam.annotations.*;
              
              @Entity
              @Name("user")
              @Scope(SESSION)
              @Table(name="users")
              
              public class User implements Serializable {
              
               private static final long serialVersionUID = 5139654161684162176L;
               private long id;
               private String first;
               private String last;
               private String username;
               private String password;
               private Date createdate;
              
               public User (String first, String last, String username, String password) {
               this.first = first;
               this.last = last;
               this.username = username;
               this.password = password;
               createdate = new Date();
               }
              
               public User () {
              
               }
              
               @NotNull
               public Date getCreatedate() {
               return createdate;
               }
               public void setCreatedate(Date createdate) {
               this.createdate = createdate;
               }
               @NotNull
               public String getFirst() {
               return first;
               }
               public void setFirst(String first) {
               this.first = first;
               }
               @Id(generate=AUTO) @NotNull
               public long getId() {
               return id;
               }
               public void setId(long id) {
               this.id = id;
               }
               @NotNull
               public String getLast() {
               return last;
               }
               public void setLast(String last) {
               this.last = last;
               }
               @NotNull
               public String getPassword() {
               return password;
               }
               public void setPassword(String password) {
               this.password = password;
               }
               @NotNull
               public String getUsername() {
               return username;
               }
               public void setUsername(String username) {
               this.username = username;
               }
              
              
              
              }
              


              usercreate.jsp

              
              <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
              <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
              <html>
               <head>
               <title>Create New User</title>
               </head>
               <body>
               <f:view>
               <h:form>
               <table border="0">
               <tr>
               <td>Username</td>
               <td><h:inputText value="#{user.username}"/></td>
               </tr>
               <tr>
               <td>First Name</td>
               <td><h:inputText value="#{user.first}"/></td>
               </tr>
               <tr>
               <td>Last Name</td>
               <td><h:inputText value="#{user.last}"/></td>
               </tr>
               <tr>
               <td>Password</td>
               <td><h:inputSecret value="#{user.password}"/></td>
               </tr>
               </table>
               <h:messages/>
               <h:commandButton type="submit" value="Register" action="#{userutils.createUser}"/>
               </h:form>
               </f:view>
               </body>
              </html>
              
              




              Thanks in advance to anyone who can point me in the right direction...I've gone though all the examples and I must be missing something...

              • 4. Re: Seam Newbie Problem
                Gavin King Master

                If everything else is working, you can ignore that message, I think. Its MyFaces being too verbose.

                • 5. Re: Seam Newbie Problem
                  Cody Lerum Newbie

                  Wow. The last java that I wrote was 2 or 3 years ago before I was introduced to Jboss. Everything was TomCat with createing and closing connections and all by hand. Oh how things have improved.

                  Anyway I'm making really good progress on the learning curve here. But I have a question.

                  I have created a login page, mostly stealing from the booking example. Everything is working and I kick from my login page to my create user page. The problem is that I am basically carrying on the object that I logged in with. I'm assuming this as all my fields are prepopulated in my form.

                  I'm also getting the following error when I try and create a new user.

                  
                  20:30:30,747 ERROR [MethodBindingImpl] Exception while invoking expression #{userutils.createUser}
                  javax.ejb.EJBException: null; CausedByException is:
                   detached entity passed to persist: org.transaria.noc.User
                   at org.jboss.ejb3.tx.Ejb3TxPolicy.handleExceptionInOurTx(Ejb3TxPolicy.java:46)
                   at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:70)
                   at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:134)
                   at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
                   at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:61)
                   at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
                   at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:39)
                   at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
                   at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:63)
                   at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
                   at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:32)
                   at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
                   at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:91)
                   at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
                   at org.jboss.ejb3.stateless.StatelessContainer.localInvoke(StatelessContainer.java:148)
                   at org.jboss.ejb3.stateless.StatelessLocalProxy.invoke(StatelessLocalProxy.java:60)
                   at $Proxy95.createUser(Unknown Source)
                   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                   at java.lang.reflect.Method.invoke(Method.java:585)
                   at org.apache.myfaces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:138)
                   at org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:62)
                   at javax.faces.component.UICommand.broadcast(UICommand.java:106)
                   at javax.faces.component.UIViewRoot._broadcastForPhase(UIViewRoot.java:110)
                   at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:184)
                   at org.apache.myfaces.lifecycle.LifecycleImpl.invokeApplication(LifecycleImpl.java:271)
                   at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:102)
                   at javax.faces.webapp.FacesServlet.service(FacesServlet.java:109)
                   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
                   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
                   at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:81)
                   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
                   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
                   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
                   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
                   at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:39)
                   at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:159)
                   at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:59)
                   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
                   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
                   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
                   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
                   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
                   at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
                   at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
                   at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
                   at java.lang.Thread.run(Thread.java:595)
                  
                  


                  
                  @Stateless
                  @Name("login")
                  @Scope(EVENT)
                  @Interceptor(SeamInterceptor.class)
                  public class LoginAction implements Login {
                  
                   @In @Out
                   private User user;
                  
                  
                   @PersistenceContext
                   private EntityManager em;
                  
                   @In
                   private Context sessionContext;
                   @In
                   private FacesContext facesContext;
                  
                   public String login() {
                   List<User> results = em.createQuery("from User where username=:username and password=:password")
                   .setParameter("username", user.getUsername())
                   .setParameter("password", user.getPassword())
                   .getResultList();
                  
                   if ( results.size()==0 )
                   {
                   facesContext.addMessage(null, new FacesMessage("Invalid login"));
                   return "login";
                   }
                   else
                   {
                   user = results.get(0);
                   sessionContext.set("loggedIn", true);
                   return "main";
                   }
                   }
                  
                  }
                  
                  


                  package org.transaria.noc;
                  
                  import static org.jboss.seam.ScopeType.EVENT;
                  
                  import java.util.List;
                  import javax.ejb.Interceptor;
                  import javax.ejb.Stateless;
                  import javax.persistence.EntityManager;
                  import javax.persistence.PersistenceContext;
                  import org.hibernate.validator.Valid;
                  import org.jboss.seam.annotations.IfInvalid;
                  import org.jboss.seam.annotations.In;
                  import org.jboss.seam.annotations.Name;
                  import org.jboss.seam.annotations.Outcome;
                  import org.jboss.seam.annotations.Scope;
                  
                  import javax.faces.application.FacesMessage;
                  import javax.faces.context.FacesContext;
                  import org.jboss.seam.ejb.SeamInterceptor;
                  
                  @Stateless
                  @Scope(EVENT)
                  @Name("userutils")
                  @Interceptor(SeamInterceptor.class)
                  @LoggedIn
                  public class UserUtilsAction implements UserUtils {
                  
                   @In @Valid
                   private User user;
                  
                   @PersistenceContext
                   private EntityManager em;
                  
                   @In
                   private FacesContext facesContext;
                  
                   @IfInvalid(outcome=Outcome.REDISPLAY)
                   public String createUser() {
                   List existing = em.createQuery("select username from User where username=:username")
                   .setParameter("username", user.getUsername())
                   .getResultList();
                  
                   if (existing.size()==0)
                   {
                   em.persist(user);
                   return "created";
                   }
                   else
                   {
                   facesContext.addMessage(null, new FacesMessage("username already exists"));
                   return null;
                   }
                   }
                  
                  }
                  
                  


                  I want to retain information from my users login, but I also need only users who have logged to have the ability to create users.....so does the create need to be a seperate conversation off the first?

                  How would I go about doing this, can someone point me in the right direction?



                  • 6. Re: Seam Newbie Problem
                    Gavin King Master

                     

                    "mutpup" wrote:
                    The problem is that I am basically carrying on the object that I logged in with.

                    I want to retain information from my users login, but I also need only users who have logged to have the ability to create users.....so does the create need to be a seperate conversation off the first?


                    Probably the nicest approach for you is to try out the new @Roles feature that I just committed to CVS. Other approaches include using an indirection between the scoped seam component and the actual User object. So instead of getting the User directly bound to a context variable, you do stuff like #{currentLogin.user} and #{userEditor.user}.

                    • 7. Re: Seam Newbie Problem
                      Cody Lerum Newbie

                      So I would need a seperate bean to provide access to the entity bean?

                      Also I think part of my problem is the whole Scope and Stateful/Stateless isn't really gel'd in my mind. Can someone point me in the direction of a page that explains it well?

                      • 8. Re: Seam Newbie Problem
                        Cody Lerum Newbie

                        eh...I just looked into the roles yeah that is a much better fit.

                        Guess I'm going to learn how hard it is to build jboss outta the CVS. I will acutally be out of touch with all of this till Monday.

                        Should I wait, or what is the ETA for the RC of 4.0.4? Will it work with the CVS ver of seam?

                        • 9. Re: Seam Newbie Problem
                          Matthew Edwards Newbie

                          Do a internet search for WinCVS.
                          Install it.
                          Start it up.
                          Press cntrl + L
                          Copy and paste the cvs location string into the text window and press OK.
                          You can find it here: http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3917624#3917624

                          It will download it automatically.
                          Then browse to the location the project was copied to on your computer.
                          Select the build folder (or whichever folder has the build.bat file in it) and double click build.bat
                          It will download what it needs off the internet and then compile itself.

                          Then copy/paste the generated folder to the location you want JBoss in.

                          • 10. Re: Seam Newbie Problem
                            Gavin King Master

                            4.0.4 goes out as soon as Scott finishes the QA cycle (ie. gets people to fix some broken tests).

                            I am basically just in a holding pattern until then :(