[jboss-user] [JBoss Seam] - Re: simeple create/edit user question

bfo81 do-not-reply at jboss.com
Wed Aug 9 04:59:42 EDT 2006


Stateless beans are only useful if you want to invoke one of their methods without doing anything else with them.

But if you have a state that should be held (e.g. user filled in fields) you need a STATEFUL bean. To distinguish between new and existing entities you can call two different actions - create and edit. There should be corresponding clickable buttons in your application.

I suggest it like that (pseudo code - in your case replace Entity by User):


  | @Stateful
  | @Scope(ScopeType.CONVERSATION)
  | @Name(...)
  | public class WhatEverBean implements WhatEver {
  | 
  |     private boolean newOne;
  | 
  |     @PersistenceContext(PersistenceContextType.EXTENDED)
  |     private EntityManager em;
  | 
  |     @In(required=false) @Out(required=false)
  |     private Entity entity;
  | 
  |     @Begin
  |     public String create() {
  |         newOne = true;
  |         entity = new Entity();
  |         return "editPageOutcome";
  |     }
  | 
  |     @Begin
  |     public String edit() {
  |         newOne = false;
  | 
  |         entity = em.find(Entity.class, theIdFromRequestParameter);
  | OR:   entity = getFromDataModelSelection...;
  | 
  |         return "editorPageOutcome";
  |     }
  | 
  |     @End
  |     public String save() {
  |         if (newOne)
  |             em.persist(entity);
  |         else
  |             em.merge(entity);
  |         return "toPreviousPageOutcome";
  |     }
  | }

Ok, why do I suggest conversation scope? Cause the bean needs to live as long as the user edits the entity (including redisplays).

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

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



More information about the jboss-user mailing list