[jboss-user] [JBoss Seam] - Re: Problems with list page, persistence, and detached entit

Oberiko do-not-reply at jboss.com
Fri Jan 18 17:07:15 EST 2008


It seems to work just as well by using the conversation scope, with less code and, of course, a smaller footprint.


  | package org.domain.myProject.session;
  | 
  | import static javax.persistence.PersistenceContextType.EXTENDED;
  | 
  | import java.util.List;
  | 
  | import javax.ejb.Remove;
  | import javax.ejb.Stateful;
  | import javax.persistence.EntityManager;
  | import javax.persistence.PersistenceContext;
  | 
  | import org.domain.myProject.entity.User;
  | import org.domain.myProject.session.local.EditUserLocal;
  | import org.jboss.seam.ScopeType;
  | import org.jboss.seam.annotations.Begin;
  | import org.jboss.seam.annotations.Destroy;
  | import org.jboss.seam.annotations.End;
  | import org.jboss.seam.annotations.Factory;
  | 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.annotations.Scope;
  | import org.jboss.seam.annotations.datamodel.DataModel;
  | import org.jboss.seam.annotations.datamodel.DataModelSelection;
  | import org.jboss.seam.faces.FacesMessages;
  | import org.jboss.seam.log.Log;
  | 
  | @Stateful
  | @Name("editUser")
  | @Scope(ScopeType.CONVERSATION)
  | public class EditUserForm implements EditUserLocal {
  | 
  |     @Logger 
  |     private Log log;
  |     
  |     @In 
  |     FacesMessages facesMessages;
  |     
  |     @PersistenceContext(type = EXTENDED)
  |     private EntityManager em;
  |     
  |     @DataModelSelection
  |     @Out(required=false)
  |     private User user;
  | 	  
  |     @DataModel
  |     private List<User> users;
  |     
  |     @SuppressWarnings("unchecked")
  | 		@Factory("users")
  | 		@Begin
  |     public void findUsers(){
  |     	log.info("*********************************************  Finding the users");
  |     	if (users == null)
  |     		log.info("users is null");
  |     	else if (users.size() == 0)
  |     		log.info("users has a size of zero");
  |     	else
  |     		log.info("Strange, because users has " +users.size() + " entries");
  |     	
  |     	users = em.createQuery("from User u").getResultList();
  |     }
  |     
  |     public void remove(){
  |     	log.info("Deleting " +user.getName());
  |     	em.remove(user);
  |     	users.remove(user);
  |     }
  | 
  |     @End
  |     public void clear(){
  |     	//We're clearing user since it is being outjected and would otherwise populate the entry page.
  |     	user = null;
  |     }
  | 		
  |     public void update() {
  |     	log.info("Updating " + user.getId());
  |     	em.persist(user);
  |     }
  |     
  |     @Destroy @Remove                                                                      
  |     public void destroy() {}
  | }
  | 

Using it like this though, doesn't require the ScopeType.PAGE at all, which was what I originally wanted.

Is this kind of situation just not applicable to using the PAGE scope?  If not, when would we use it?

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

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



More information about the jboss-user mailing list