• 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: SOLVED Question for the Java Gurus
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: SOLVED Question for the Java Gurus


  • Subject: Re: SOLVED Question for the Java Gurus
  • From: Sam Barnum <email@hidden>
  • Date: Fri, 23 Apr 2004 09:11:46 -0700

Owen,
Sounds like you're making this more complicated than it needs to be. WebObjects will take care of the to-many join for you. When you set the array related objects, it sets the relationships for you.


So for your array of checkboxes, try using a WOCheckboxMatrix. Bind the list to all items you want to select from, and bind the 'selections' to the to-many relationship of the object. Should all sort itself out.

You might want to take a look at the  WOEditToMany  component.


On Apr 22, 2004, at 5:40 PM, Owen McKerrow wrote:

On 23/04/2004, at 12:01 AM, Sam Barnum wrote:

Or, just use NSArray's valueForKey() method, which calls valueForKey() for each item in an array

NSArray arrayOfEats; // assume this exists
NSArray arrayOfFrogs = (NSArray)arrayOfEats.valueForKey("frog");
NSArray arrayOfFoods = (NSArray)arrayOfEats.valueForKey("food");


So does it work back the other way as well ?
As in setValueForKey ?

The senario :
As an example, I have a Frequency table and a Frequency Category table, joined together by a many-to-many through a join table, jCatFreq.
Now I can't flatten the relationship as I store an order attribute in it, so that Frequencies of a particular Category are displayed correctly on the screen.


Now there could possible be lots of Frequencies to choose from so I want to display them as check box's in a WOTable.

So my understanding is that I need to rip the Frequencies the category currently owns from the join table objects ( i.e. the code that Ive been talking about in the last couple of emails ) and then compare this list with the list of all Frequencies and tick the ones that they have already selected. However then I need to be able to take back the list after it has been edited ( more objects ticked, some un-ticked etc ) and update the Categories jFeqCat array with current list of relationships it would have.

So would setValueForKey() on the array do that for me ? Will it get rid of the no longer needed items and add the new ones ?

Thanks Again
Owen


On Apr 21, 2004, at 10:06 PM, Owen McKerrow wrote:

Yeah sorry, re-read the email and yes I didn't explain myself very well. The function was just an example really, just to put the
Object tempOb = (entity)array.objectAtIndex(0); line in some form of context.


The question was basically, given the name of a class as a string, is there anyway to use that String for casting an object to the class type of class who's name is the contents of the string.

In the end I did it another way :

/**This class is deisgned to take a NSArray of objects from a join table between two entities and return a NSArray of the objects from one of the entities.
That is if you have 2 tables 'Frog' and 'Food" with the join table 'Eats' between them, you can pass this class the Frogs NSArray of Eats objects and ask for an NSArray of Food items that match the given relationship.
It only every really needs to be used when there is something in the join table that doesn't allow it to be flattened.*/



/**
Given an Array of join table objects and a relationship name, it will seek to return an array of objects from the other side of that relationship
@param objects The array of objects you wish to strip
@param relationship The relationship that you wish to get an array of objects from
*/
public static NSMutableArray stripJoin(NSArray objects, String relationship) throws Exception
{
int i;
NSMutableArray wantedObjects = new NSMutableArray();
for (i=0;i < objects.count();i++) {
Object temp = objects.objectAtIndex(i);
Method tempMethod = temp.getClass().getMethod(relationship,null);
wantedObjects.addObject(tempMethod.invoke(temp,null));
}
return wantedObjects;
}


Owen



- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
People who prefer typing to pointing then seem to prefer acronyms to save typing :-)
-Denis Stanton, On people using Command Line Interfaces
_______________________________________________
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.
_______________________________________________
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: 
 >Question for the Java Gurus (From: Owen McKerrow <email@hidden>)
 >Re: Question for the Java Gurus (From: Art Isbell <email@hidden>)
 >Re: SOLVED Question for the Java Gurus (From: Owen McKerrow <email@hidden>)
 >Re: SOLVED Question for the Java Gurus (From: Owen McKerrow <email@hidden>)

  • Prev by Date: Re: Apache SSI and WebObjects
  • Next by Date: Re: Date calculation
  • Previous by thread: Re: SOLVED Question for the Java Gurus
  • Next by thread: Re: Question for the Java Gurus
  • Index(es):
    • Date
    • Thread