• 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
Re: WOPopupButton - want a value list for a foreign key
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: WOPopupButton - want a value list for a foreign key


  • Subject: Re: WOPopupButton - want a value list for a foreign key
  • From: Art Isbell <email@hidden>
  • Date: Sun, 15 Dec 2002 14:40:29 -1000

On Saturday, December 14, 2002, at 03:54  PM, Thomas Peters wrote:

I want to fill a WOPopupButton with the values from a parent object. I found
an example that uses an NSArray. However, I wonder if I should handle things a
little differently than this:


    public static NSArray getCategoryNames() {
         return (NSArray)allCategories().valueForKey("categoryName");
    }

public static NSArray allCategories() {
EOSharedEditingContext ec = session().defaultSharedEditingContext();
EODatabaseDataSource ds = new EODatabaseDataSource(ec,
"ProductCategory");


        return ds.fetchObjects();
    }

I'm not sure how WO will work if these methods are static. They would normally be instance, not class methods.


This works to fill the menu with names, but my Category data has cat_id &
cat_name. The foreign key in product is cat_id.

Only in rare, unusual situations should you worry about primary and foreign key values when using EOF. Neither should be a class property in your eomodel (no diamond in their entry). Assuming that you have defined a to-one relationship Product.category with cat_id as the source key and the primary key of Category as the destination key, you should manipulate the Product.category relationship instead.


I am trying to create a
WOComponent that has a popup with the categories. I have the popup list bound
the the getCategoryNames.


Some questions:
Is it better to use NSArray or should I create another displayGroup in the
WOComponent?

Many WO programmers don't use display groups at all. They're certainly not necessary. They do offer a batch display capability that's nice, but otherwise, accessing objects via the underlying editing context works fine.


public NSArray allCategories() {
EOSharedEditingContext ec = session().defaultSharedEditingContext();
return EOUtilities.objectsOfClass(ec, "ProductCategory");
}


If I create a categoryDisplayGroup, how should I setup the bindings for the
WOPopupButton?

This assumes that "product" is the current Product object whose "category" relationship you want to set:


	displayString: categoryItem.categoryName
	item: categoryItem
	list: categoryDisplayGroup.allObjects
	selection: product.category

  How can I create a multi-dimensional NSArray that stores the cat_id &
cat_name from the ProductCategory EObject?

Again, foreign keys aren't normally referenced in the Java code. allCategories() will return an array of ProductCategory objects that contain all of the properties set as class properties in the eomodel. getCategoryNames() is ferreting out the categoryName attribute for each ProductCategory object, but you could access any other class property as well.


Art
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >WOPopupButton - want a value list for a foreign key (From: "Thomas Peters" <email@hidden>)

  • Prev by Date: Re: Demonstrations Run Errors
  • Next by Date: Ok, so refetch() is deprecated in EOEditingContext...
  • Previous by thread: WOPopupButton - want a value list for a foreign key
  • Next by thread: Demonstrations Run Errors
  • Index(es):
    • Date
    • Thread