package org.domain.myProject.session; import javax.ejb.Stateless; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; import org.domain.myProject.entity.User; import org.domain.myProject.session.local.SaveUserLocal; import org.jboss.seam.annotations.In; import org.jboss.seam.annotations.Logger; import org.jboss.seam.annotations.Name; import org.jboss.seam.annotations.Out; import org.jboss.seam.faces.FacesMessages; import org.jboss.seam.log.Log; @Stateless @Name("saveUser") public class SaveUserAction implements SaveUserLocal { @Logger private Log log; @In FacesMessages facesMessages; @PersistenceContext private EntityManager em; /* We have an '@Out' on this to push back user (after any modifications we make * in our bean here) onto the page. Since we're nullifying user in our save method, * we need to state that it's not required to have any value. */ @In @Out(required=false) private User user; public void saveUser() { //Simple persisting with the EntityManager em.persist(user); //Note that the id of our user was generated and populated. facesMessages.add("User was saved with an id of "+ user.getId()); log.info(user.getName() +" was saved."); //We're nullifying user so that the page is blank after saving. user = null; } }