• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Custom class with D2W
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Custom class with D2W


  • Subject: Custom class with D2W
  • From: Pete Rive <email@hidden>
  • Date: Wed, 9 Nov 2005 09:43:43 +1300

Thanks a lot Robert,

Yes, I realised after I sent it that I had omitted to say that I had already created the EOGenericRecord custom class, named "Idea" through EOModeller. "Idea" is the entity and "value" is the attribute. I have gone back and corrected a few lines of code but I am now just have one remaining error:

Idea.java:121: cannot resolve symbol
symbol  : method setValue (java.math.BigDecimal)
Build failed for target "BigIdeaD2W" using build style "Development" (1 error)

This is from:

public void awakeFromInsertion (EOEditingContext ec) {
super.awakeFromInsertion(ec);
if (value() == null) {
setValue(new BigDecimal("500"));
}
}
}

Any thoughts?
Cheers
Pete



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


 _______________________________________________
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

  • Follow-Ups:
    • Re: Custom class with D2W
      • From: Robert Walker <email@hidden>
    • Re: Custom class with D2W
      • From: David Teran <email@hidden>
  • Prev by Date: Re: plist problem
  • Next by Date: NSURLErrorDomain:-1005 with WOMetaRefresh
  • Previous by thread: Re: Custom class with D2W
  • Next by thread: Re: Custom class with D2W
  • Index(es):
    • Date
    • Thread