Re: Setting a Default toOne Relationship
Re: Setting a Default toOne Relationship
- Subject: Re: Setting a Default toOne Relationship
- From: David Avendasora <email@hidden>
- Date: Fri, 19 May 2006 11:02:01 +0100
- Resent-date: Fri, 19 May 2006 11:08:09 +0100
- Resent-from: David Avendasora <email@hidden>
- Resent-message-id: <email@hidden>
- Resent-to: Development WebObjects <email@hidden>
Hi Ken,
The objects must get inserted upon instantiation. What would the
point be of having a context that you don't use until you save the
information to the database? Might just as well do direct JDBC calls
then.
According to the WebObjects Java Client Programming Guide (http://
developer.apple.com/documentation/WebObjects/DesktopApplications/
WODesktopApps.pdf), Chapter 6, the section on specifying initial
values (page 123) if you add setters in the awakeFromInsertion()
method, these values will show up immediately.
See below:
<CLIP>
Initial Values
When you create a new record, you might want to supply some default
values for the fields in that record. Although none of the fields in
the Student record really need a default value, you’ll override
awakeFromInsertion in order to learn how to give a field a default
value.
Add this code in the server-side Student.java file:
public void awakeFromInsertion(EOEditingContext context) {
super.awakeFromInsertion(context);
if (gpa() == null) {
setGpa(new BigDecimal("0"));
}
if (sat() == null) {
setSat(new BigDecimal("0"));
}
if (act() == null) {
setAct(new BigDecimal("0"));
}
if (name() == null) {
setName("");
}
}
Build and run the application and create a new student record. You’ll
notice that some of the fields are populated in the new record as
shown in Figure 6-11.
Figure 6-11 Initial values
</CLIP>
On May 19, 2006, at 10:48 AM, Ken Anderson wrote:
David,
I would guess that the object won't actually get inserted into the
context on the server side until you try to save. I could be
wrong, since I've never done Java client work before, but that's
what I would suspect. Can you confirm or deny this?
I suggest doing some experiments saving the object to see when
awakeFromInsertion() gets called on the server side...
Ken
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden