Hi Angelo,

A couple of comments below.

Cheers, Geoff

On 29/11/2007, at 1:48 AM, Angelo Chen wrote:

- whenever there's an error, cat is being loaded twice, because
onActivate() is called before and after onValidate().
<ac> yes, that will be loaded twice, but the second time is not being
used, it's simply a useless loading, it does not affect the operation, I
think.

Yes, since you're using Open Session In View, the second load will be in the same transaction and will therefore be a very cheap operation.

T5's request/render mechanism works very well when there is no form
involved, when the form is there, confusion starts, i believe, it's a
matter of finding a way to use it properly, thanks.

As you've seen in this mailing list I am also having trouble once forms are involved. No solution seems to cover all the bases, but I am going to keep looking. See my post earlier today: 'T5: Is Perisst("conversation") planned? Please?'.


A.C.

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]




--
View this message in context: 
http://www.nabble.com/T5%3A-CRUD-basic-practice--tf4885903.html#a13993908
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