However, I can't work out whether this code is appropriate for a
Direct to Web app and what Java file to annotate eg
Application.Java, DirectAction.Java etc ? I have started to try
and learn Java to work it out but it could take awhile.
Sorry for the additional reply, but I just noticed this line. The
awakeFromInsertion() method goes in the EOGenericRecord subclass for
your enterprise object.
Assume your entity in your model was named "Item" and Item had an
attribute named "value." Then you would set the Class in the model
to "Item" or "com.mycompany.Item" and create a subclass of
EOGenericRecord.
Example class file:
File Name: Item.java
import com.webobjects.foundation.*;
import com.webobjects.eocontrol.*;
import com.webobjects.eoaccess.*;
import java.math.BigDecimal;
import java.util.*;
public class Item extends EOGenericRecord {
public Item() {
super();
}
/*
* Class attributes
*/
public BigDecimal value() {
return (BigDecimal)storedValueForKey("value");
}
/*
* To-one relationships
*/
/*
* To-many relationships
*/
/*
* Custom business logic
*/
public void awakeFromInsertion(EOEditingContext ec) {
super.awakeFromInsertion(ec);
if (value() == null)
setValue(new BigDecimal("500");
}
}
There are a number of different ways to generate these class files.
EOModeler can create them for you, or you may prefer to use a tool
like EOGenerator to create them for you. If you are interested in
EOGenerator you can do a search on this list, there are many
references to it.
On Nov 7, 2005, at 5:19 PM, Robert Walker wrote:
public void awakeFromInsertion(EOEditingContext context) {
super.awakeFromInsertion(context);
if (value() == null) {
setValue(new BigDecimal("500"));
}
}
}
This is very appropriate for setting default values in any
WebObjects application, no matter the type. For D2W this code
would exist in your custom subclass of your enterprise object (on
the server-side class, of course, since only server-side exists in
D2W). This code would then continue to work just fine as you move
from your D2W prototype application to your production web
application.
The primary purpose of the awakeFromInsertion() method is to keep
enterprise object initialization logic inside the model layer of
the MVC design pattern. This enhances the reusability of your
business logic.
On Nov 7, 2005, at 4:44 PM, Pete Rive wrote:
Hi to all you WO masters of the universe,
I am a newbie trying to build a D2W app. I started out looking at
a Java Client app but decided to change to a D2W.
I am trying to customise some business logic that will allow
automatically include a value when a new record is added to the
database. In Direct to Java I used the following code on the App
server which did what I wanted it to do:
public void awakeFromInsertion(EOEditingContext context) {
super.awakeFromInsertion(context);
if (value() == null) {
setValue(new BigDecimal("500"));
}
}
}
ie. When any new record was added it would automatically have a
value "500".
However, I can't work out whether this code is appropriate for a
Direct to Web app and what Java file to annotate eg
Application.Java, DirectAction.Java etc ? I have started to try
and learn Java to work it out but it could take awhile.
Does anyone have any suggestions?
Cheers
Pete