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?



View the original post : 
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3919490#3919490

Reply to the post : 
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3919490


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
_______________________________________________
JBoss-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to