• 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 bind to database and dynamic dependant ( newbie question )
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: WOPopupButton bind to database and dynamic dependant ( newbie question )


  • Subject: Re: WOPopupButton bind to database and dynamic dependant ( newbie question )
  • From: Art Isbell <email@hidden>
  • Date: Mon, 10 Feb 2003 17:00:14 -1000

On Sunday, February 9, 2003, at 08:20  PM, Alvaro Muir wrote:

1. I have created an EOModel of my database, really a small DB with just one
table. Lets suppose its a small db of sports as follows:


teamID  | state |   city    |     sport   |   team
----------------------------------------------------
0101       NY     NY           basketball    Knicks
0102       NY     NY           baseball      Yankees
0103       NY     Buffalo      football      Bills
0304       FL     Miami        footballl     Dolphins
0302       FL     Miami        basketball    Heat
0310       FL     Orlando      basketball    Magic
0320       FL     Tampa        football      Buccaneers
0330       FL     Jacksonville football      Jaguars

2. I would like to bind WOPopupButton to a certain table, lets say the State

That would be "a certain attribute".

with a basic SQL query like "SELECT DISTINCT state from TEAMTABLE", to
return just the states, one time only.

Your eomodel defines which attributes will be selected based on those marked as class properties (diamond symbol). So you should mark all properties that you will use in your app, not just of a particular fetch, as class properties. These class properties don't normally include primary and foreign keys which are ideally meaningless integers. Because you want to use state, city, sport, and team attributes, all should be class properties. So the SQL for the resulting fetch would be "select state, city, sport, team from teamtable".


Fetching "one time only" can mean several things. If your fetched objects aren't likely to be modified, created, or deleted during the lifetime of your Web process, they can be marked as shared in your model and fetched once into an EOSharedEditingContext when your app is started. Then they can be accessed from any component without another fetch occurring.

If they don't meet the above criteria, they can be fetched once during each user session, stored in a "sportTeams" NSArray in your Session object, and accessed without subsequent refetches using a Session accessor method, "sportTeams()". You would then manipulate this array of sport teams to populate your popups rather than accessing the DB repeatedly.

3. From that, I would like my next WOPopupButton to populate based on the
previous selection. I.e., If "FL" was selected, the next WOPopupButton
should only have FL cities, like Orlando, Jacksonville, Tampa, Miami, blah
blah. Then down the line to populate the other WOPopups based on previous
selection.

Sure, that's doable as long as you understand that popup population must occur on the Web server. So after each popup selection is made, the page must be submitted so the next popup can be populated accordingly. The resulting page refreshes may not be ideal, but that's for you and your users to decide.


So my question is two-tier. First binding my WOPopup button to my already
created EOModle database, and secondly ( if possible ) how to create dynamic
dependant WOPopupButtons.

The State popup's "list" key must be bound to an array of state string objects, a component instance variable "states", created from the Session.sportTeams array, for example. There are undoubtedly several ways to do this, but I'd first create an array of all state strings:


	states = session().sportTeams().valueForKey("state");

This will contain dupes, so create an NSSet from this states array to remove the dups:

	NSSet uniqueStates = new NSSet(states);

But a popup expects an array to be bound to its "list" key, so extract an array from this set:

	states = uniqueStates.allObjects();

Displaying this states list in alphabetical order, a desirable feature, is left as an exercise for the reader :-)

The popup's "list" key would be bound to "states". The "selection" key would be bound to a component variable of type SportTeam, "state", that will be used to determine the content of the Cities popup. A way to do that would be to take advantage of in-memory qualifying provided by EOQualifier:

EOQualifier qualifier = EOQualifier.qualifierWithQualifierFormat("state = %@", new NSArray(state));
cities = EOQualifier.filteredArrayWithQualifier (session().sportTeams(), qualifier);


cities, another component instance variable, would be bound to the Cities popup's "list" key. And so on down the line of popups. A desirable feature would be to place each popup button in a WOConditional that would prevent it from being displayed until a selection had been made in its predecessor popup.

None of my example code has been tested and is probably broken, but it should at least get you started.

Art
http://homepage.mac.com/aisbell/
_______________________________________________
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 bind to database and dynamic dependant ( newbie question ) (From: Alvaro Muir <email@hidden>)

  • Prev by Date: Re: Java client w/o Interface Builder
  • Next by Date: Re: Intersystems Caché
  • Previous by thread: WOPopupButton bind to database and dynamic dependant ( newbie question )
  • Next by thread: Intersystems Caché
  • Index(es):
    • Date
    • Thread