Re: WOPopUpButton queston
Re: WOPopUpButton queston
- Subject: Re: WOPopUpButton queston
- From: Gustavo Pizano <email@hidden>
- Date: Sun, 23 Mar 2008 22:48:24 -0500
OH NO NO NO I was wrong I can't do that. in the _Person EO, the
name() will return me the name of the current instance.. hehehe
so i do need at least the setters
no?
Gus
On Mar 23, 2008, at 10:03 PM, Lachlan Deck wrote:
Hi Gustavo,
On 23/03/2008, at 2:32 PM, Gustavo Pizano wrote:
private StudyLevel studyLevel;
unless you've got a public getter the above should be public.
studies =
StudyLevel.fetchAllStudyLevels(session().defaultEditingContext());
PopUpButton : WOPopUpButton {
list = studies;
item = studyLevel;
displayString = studyLevel.name;
noSelectionString = "------------------" ;
}
so I will get a list with the "name" attribute, anyway I was
reading the api, and I see that I have 2 optins but I don't get
tehm clear
The two options (selection, selectedValue) are there as it depends
on the method by which someone comes/responds to your page. i.e.,
DirectAction (i.e., usually session-less pages) or ComponentAction
(i.e., session-based pages).
I'm guessing that you're not using direct actions, so you'll want to
bind selection to the key that returns the selected studyLevel (or
null if no selection has been made).
which one should I use, so when submitting I will send the "id"
atrribute only to the Person table?.
No. When using EOF/WO in code, you'll need to learn to forget about
ids and foreign keys. These are, for the most part, considered
database artefacts. Instead think in OO terms (i.e., relationships).
So if I, for example, have a Person who can have one studyLevel such
that in the model you have:
Person:
(non-class attributes)
id (i.e., pk)
studyLevelID (i.e., foreign key)
(class attributes)
* firstName
* lastName
* email
(relations)
studyLevel (joins on studyLevelID, StudyLevel.id)
Then in code I would do this based on the selection:
//
// Note the var and get/set methods for selectedStudyLevel can go
away by binding
// in your wod to person.studyLevel.
//
public class YourComponent
{
private EOEditingContext ec;
private Person person;
private StudyLevel selectedStudyLevel;
public StudyLevel studyLevelItem;
public NSArray studyLevelsOptions;
public YourComponent( WOContext context )
{
super( context );
}
public EOEditingContext editingContext()
{
return session().defaultEditingContext();
}
private EOEnterpriseObject getLocalInstance( EOEnterpriseObject eo )
{
if ( eo == null || eo.editingContext() == editingContext() )
return eo;
return EOUtilities.localInstanceOfObject( editingContext(), eo );
}
public Person getPerson()
{
if ( this.person == null )
setPerson
( ( Person )EOUtilities.createAndInsertInstance( editingContext(),
Person.ENTITY_NAME ) );
return this.person;
}
public StudyLevel getSelectedStudyLevel()
{
return this.selectedStudyLevel;
}
public NSArray getStudyLevelOptions()
{
if ( studyLevelOptions == null )
studyLevelOptions =
StudyLevel.fetchAllStudyLevels( editingContext() );
return studyLevelOptions;
}
public void setPerson( Person person )
{
this.person = ( Person )getLocalInstance( person );
if ( this.person != null )
setSelectedStudyLevel( getPerson().studyLevel() );
}
public void setSelectedStudyLevel( StudyLevel level )
{
this.selectedStudyLevel = ( StudyLevel )getLocalInstance( level );
//
// if your intention is to set the relationship between Person and
StudyLevel:
// then really, dump the getter/setter and variable for this and
just
// bind to it in the wod file via person.studyLevel.
// OR you can do something like the following....
//
if ( getPerson().studyLevel() != null )
getPerson
().removeObjectFromBothSidesOfRelationshipWithKey
( getPerson().studyLevel(), Person.STUDY_LEVEL_KEY );
if ( this.selectedStudyLevel != null )
getPerson
().addObjectToBothSidesOfRelationshipWithKey
( getSelectedStudyLevel(), Person.STUDY_LEVEL_KEY );
}
}
Other thing that Im coming to, is that I need to register 1 or more
Specialities, how can I do that?, I was thinking in put a button
(link whatever) "Add Speciality", so dynamically will appear
fields to choose the speciality, and then when pressing save it
will save it, and so on.I dunno I guess there is a better and
easier way to achieve this.
what im thinkin is that I can't disaplay the specialities options
in a WOPopUpButton becuase I have like 1100 specilaityes, so any
ideas??
Ah the joys of interfaces. There are countless options. Radio,
Popup, paged lists, etc.
with regards,
--
Lachlan Deck
_______________________________________________
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
_______________________________________________
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