• 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: ClassCastException???
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: ClassCastException???


  • Subject: Re: ClassCastException???
  • From: Guido Neitzer <email@hidden>
  • Date: Thu, 2 Oct 2008 12:42:18 -0600


On 2-Oct-08, at 12:17 PM, Awbrey Hughlett wrote:

My bindings:
BasicType : WOPopUpButton {
list = allBasicTypes;
item = aBasic;
displayString = aBasic.listingType;
selection = aBasic;
}

That should be:

selection = listing.basic;

SpecificType : WOPopUpButton {
list = allSpecificTypes;
item = aSpecific;
displayString = aSpecific.specificType;
selection = aSpecific;
}

selection = listing.specific;

My code (after specified changes):
public class DataEntry extends WOComponent {
private Listing listing;
private EOEditingContext ec = editingContext();
public Basic aBasic = aBasic();
public Specific aSpecific = aSpecific();

public Basic aBasic;
public Specific aSpecific;

You are creating objects again that are hanging around!

What happens there is that the popup button will iterate over the array of objects and set the "item" binding to null when it's done. When you then access your aBasic() methods you create a new one that is unrelated, in no editing context and just plain dangling around.

    public Basic aBasic() {
    if (aBasic == null) {
    aBasic = new Basic();
    }
    return aBasic;
    }

Get rid of that, completely.

    public Specific aSpecific() {
    if (aSpecific == null) {
    aSpecific = new Specific();
    }
    return aSpecific;
    }

Same for that. 

Or, better style, make your aBasic and aSpecific private and use simple getters and setters. Do NOT create an object there. You try to do the tools work here. That will always fail. Never fight WebObjects, it will win. Always!

    public Listing listing() {
    if (listing == null) {
    ec.revert();
    
    listing = (Listing)EOUtilities.createAndInsertInstance(ec, "Listing");
    ec.insertObject(aBasic);
    ec.insertObject(aSpecific);
    }
    
    return listing;
    }

Don't do the insertObject for the basic and specific here! 

    public NSArray allSpecificTypes() {
    return EOUtilities.objectsForEntityNamed(ec, "Specific");
    }

You might want to cache that in an ivar later.

    
    public NSArray allBasicTypes() {
    return EOUtilities.objectsForEntityNamed(ec, "Basic");
    }

Same here.

    public WOComponent saveChanges() {
    
    listing().setLastModified(new NSTimestamp());
    listing().addObjectToPropertyWithKey(aSpecific, "specific");
    listing().addObjectToPropertyWithKey(aBasic, "basics");

Don't do the addObject... here. It is done by the tool when you set the selection binding of the WOPopUpButton properly.

In the second you are here, aSpecific/aBasic are null. Don't use them. They are only helpers while WO is iterating over the list of objects.

From what I can see, that should then work.

cug


-- 
Real World WebObjects Bootcamp at the Big Nerd Ranch:
http://www.bignerdranch.com/classes/real-world_webobjects.shtml

 _______________________________________________
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: 
 >Relationships (From: Awbrey Hughlett <email@hidden>)
 >Re: Relationships (From: Chuck Hill <email@hidden>)
 >ClassCastException??? (From: Awbrey Hughlett <email@hidden>)
 >Re: ClassCastException??? (From: Johann Werner <email@hidden>)
 >Re: ClassCastException??? (From: Awbrey Hughlett <email@hidden>)
 >Re: ClassCastException??? (From: Guido Neitzer <email@hidden>)
 >Re: ClassCastException??? (From: David LeBer <email@hidden>)
 >Re: ClassCastException??? (From: Guido Neitzer <email@hidden>)
 >Re: ClassCastException??? (From: Awbrey Hughlett <email@hidden>)

  • Prev by Date: Re: Question about search performance
  • Next by Date: Re: ClassCastException???
  • Previous by thread: Re: ClassCastException???
  • Next by thread: Re: ClassCastException???
  • Index(es):
    • Date
    • Thread