• 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: Basic question - lightweight to-one relationship from entity to POJO/enum
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Basic question - lightweight to-one relationship from entity to POJO/enum


  • Subject: Re: Basic question - lightweight to-one relationship from entity to POJO/enum
  • From: Mark Wardle <email@hidden>
  • Date: Fri, 9 Apr 2010 21:05:46 +0100

Ramsey: thank you! I was battling the wrong binding (possibleChoices rather than restrictedChoiceKey) and have successfully updated my project's EOgenerator templates as per the objectstyle wiki.

Thank you again - I owe you more than one beer if you ever come to the UK!

Mark
--
Dr. Mark Wardle
Specialist registrar, Neurology
(Sent from my mobile)


On 9 Apr 2010, at 01:18, Ramsey Lee Gurley <email@hidden> wrote:


On Apr 8, 2010, at 5:08 PM, Mark Wardle wrote:

Ramsey: thanks for this.

More thought on this.... I should frame this as two questions: how to
adequately model a property as a java enum and how to use such a
property via conventional and D2w components.


The former isn't clear cut AFAIK. In particular, I've been bitten by
the bug (?) highlighted in this email:
http://lists.apple.com/archives/webobjects-dev/2009/Nov/msg00380.html

I only came across this when I managed to find out that I would need
to use com.eldrix.MyClass$MyEnum rather than the dot notation.

Well, you can either update templates or you can make the Enum free standing in its own java file rather than nesting it inside another class. That's what I would probably do personally, but updating templates shouldn't be all that difficult either. I just prefer to keep them separate.



Am I missing done documentation on this or do I need to update the template file as suggested in that email?

For the second issue, I see ERD2WEditToOneRelationship will handle
this although I haven't quite got the hang on the possibleChoices
binding and in particular trying to use the enum's own values getter.

All hints gratefully received!


Ok, so, you model an enum attribute, then set your componentName like you normally would

100: entity.name = 'FormEdssFull' and propertyKey = 'visualScore' => componentName = ERD2WEditToOneRelationship [Assignment]

Now all you need to do is provide a keypath that gives the list of allowable enums.

100: entity.name = 'FormEdssFull' and propertyKey = 'visualScore' => restrictedChoiceKey = "object.visualScoreChoices" [Assignment]

Which means you'll need to create a method on your FormEdssFull object like

public NSArray<VisualAcuity> visualScoreChoices() {
//TODO Based on your object state, return what possible choices are available. This just returns everything.
return new NSArray<VisualAcuity>(VisualAcuity.values());
}


And then for the display string in the popup, bind your keyWhenRelationship

100: entity.name = 'FormEdssFull' and propertyKey = 'visualScore' => keyWhenRelationship = "toString" [Assignment]

That will give you choices like

NORMAL
SIGNS_ONLY
MODERATE
MARKED

Unless you set localizeDisplayKeys of course!

100: entity.name = 'FormEdssFull' and propertyKey = 'visualScore' => localizeDisplayKeys = "true" [BooleanAssignment]

At which point you can return localized display strings by putting them into your Localizable.strings file like

"NORMAL" = "Normal";
"SIGNS_ONLY" = "Signes Seulement";
"MODERATE" = "Moderate";
"MARKED" = "Marqué";

Pardon the French if it is incorrect. Translation provided by babel fish (^_^) Anyway, I think that should work for you. Standard warnings apply: Completely untested code, your milage may vary, objects in mirror are closer than they appear ... (^_^)

Ramsey





On Thursday, April 8, 2010, Ramsey Lee Gurley <email@hidden> wrote:
For an enum specifically, you can use a custom component like

https://r2d2w.svn.sourceforge.net/svnroot/r2d2w/trunk/ERR2d2w/Components/Nonlocalized.lproj/R2D2WEditEnum.wo/

Or you can just use rules and the ERDEditToOneRelationship component. That component is flexible enough to handle the job. Spoiler: I actually plan on covering exactly this example in detail at WOWODC this year (^_^)

Ramsey

On Apr 8, 2010, at 4:52 AM, Mark Wardle wrote:

Hi all, please forgive a very simple question but I'd like to create a
lightweight (non-EO) to-one relationship from an EO. I make heavy use
of D2W so I want to fulfil the WO/EOF rules and use to-one
relationship components....


I usually create a new entity and have a genuine heavyweight EOF
relationship but I have several properties for which this seems
excessive.

I have an entity (FormEdssFull) which can have a visual field score
for both right and left eye.

Can I do this with a java enum?

public enum VisualAcuity {
NORMAL(0, "Normal"),
SIGNS_ONLY(1, "Signs only:"),
MODERATE(2, "Moderate"),
MARKED(3, "Marked");

/* insert enum constructor etc... */
}

and then create the appropriate accessor and mutator in the entity?

What do other people do in these situations?

Many thanks,

Mark

--
Dr. Mark Wardle
Specialist registrar, Neurology
Cardiff, UK
_______________________________________________
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



-- Dr. Mark Wardle Specialist registrar, Neurology Cardiff, UK

_______________________________________________
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


References: 
 >Basic question - lightweight to-one relationship from entity to POJO/enum (From: Mark Wardle <email@hidden>)
 >Re: Basic question - lightweight to-one relationship from entity to POJO/enum (From: Ramsey Lee Gurley <email@hidden>)
 >Re: Basic question - lightweight to-one relationship from entity to POJO/enum (From: Mark Wardle <email@hidden>)
 >Re: Basic question - lightweight to-one relationship from entity to POJO/enum (From: Ramsey Lee Gurley <email@hidden>)

  • Prev by Date: Re: ERXModernNavigationMenu : how to use the CSS classes ?
  • Next by Date: Re: ERXModernNavigationMenu : how to use the CSS classes ?
  • Previous by thread: Re: Basic question - lightweight to-one relationship from entity to POJO/enum
  • Next by thread: Re: Basic question - lightweight to-one relationship from entity to POJO/enum
  • Index(es):
    • Date
    • Thread