Hi Angelo,

A few concerns - none of them to do with Tapestry.

- The page is combining business logic with presentation logic rather than calling a service or a DAO. - It allows creation of a cat in an incomplete state ie. no gender or name.
- It uses neither optimistic nor pessimistic locking.

None of these is an issue if it's for a simple single-user filing system, but they could all be issues in a multi-user business system.

Actually, one Tapestry concern:

- whenever there's an error, cat is being loaded twice, because onActivate() is called before and after onValidate().

HTH,

Geoff

On 28/11/2007, at 1:36 PM, Angelo Chen wrote:


Hi,
I have been trying to find a best practice for tapestry-hibernate, looks like there is none yet, here is an approach that I would do if the tools were still dbase/Clipper at this time, very old fashion, but seems working,
no issue at all with @Persist, detached objects, any comments?

public class TestCat {

   private Cat cat;
   public String getName() { return cat.getName();}
   public void setName(String name) { cat.setName(name);}
   public String getGender() { return cat.getGender(); }
   public void setGender(String gender) {cat.setGender(gender);}

   String onSuccess(String id2) {
       if (catid == -1)
           _session.persist(cat);
       else {
           Cat oldCat = (Cat) _session.load(Cat.class, catid);
           oldCat.setGender(cat.getGender());
           oldCat.setName(cat.getName());
       }
       return null;
   }

   @Component
   private Form myForm;

   public void onValidate(String id) throws EncoderException {
       if (!cat.getGender().equals("m"))
           myForm.recordError("we are looking for male cat only");
   }

   @Inject private Session _session;

   private Long catid;

   public void onActivate(Long id) {
       catid = id;
       cat = new Cat(); // set up a buffer for editing
       if (id > 0) {  // copy contents, this might be a waste of cpu
resources, but life is easier
           Cat oldCat = (Cat) _session.load(Cat.class, id);
           cat.setGender(oldCat.getGender());
           cat.setName(oldCat.getName());
       }
   }

   public Long onPassivate() { return catid; }
}


--
View this message in context: 
http://www.nabble.com/T5%3A-CRUD-basic-practice--tf4885903.html#a13984740
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to