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]