• 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: David LeBer <email@hidden>
  • Date: Thu, 2 Oct 2008 14:42:28 -0400

OK, still some misunderstandings:

The 'item' bindings on a WOPopup (and WORepetition) needs to be bound to an instance of the type of object that is contained in array bound to the 'list' binding. As the WOPopup iterates through the array, it places the current array object into that instance. So, the item object does not need to be (AND SHOULD NOT BE) instantiated, it already exists and is in an EditingContext (the ec you used to fetch the array).

The 'selection' binding returns the object in the array that is currently selected when the form is submitted. You should NOT bind it to the item object instance you used above. If you have an object foo with a to-one relationship called 'bar' that you are trying to select a bar for, then you can bind the selection to 'foo.bar'. CAVEAT: This will not update the reverse relationship (ie: bar.foos) so if you ask bar for it's foos, the resulting array will not be correct until EOF re-faults the relationship - UNLESS you have the Project Wonder automagically update reverse relationship stuff enabled.

addObjectToBothSidesOfRelationshipWithKey does NOT create objects. It essentially does this:

	foo.addObjectToBotheSidesOfRealtionshipWithKey(bar, "bar");

	equals:

	foo.setBar(bar);
	bar.addToFoos(foo);

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

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

SpecificType : WOPopUpButton {
	list = allSpecificTypes;
	item = aSpecific;
	displayString = aSpecific.specificType;
	selection = aSpecific;
}
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 DataEntry(WOContext context) {
        super(context);
    }

    public EOEditingContext editingContext() {
    	if (ec == null) {
    		ec = ERXEC.newEditingContext();
    	}
    	return ec;
    }

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

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

public Listing listing() {
if (listing == null) {
ec.revert();

listing = (Listing)EOUtilities.createAndInsertInstance(ec, "Listing");
ec.insertObject(aBasic);
ec.insertObject(aSpecific);
}

return listing;
}


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

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

    public WOComponent saveChanges() {

    	listing().setLastModified(new NSTimestamp());
    	listing().addObjectToPropertyWithKey(aSpecific, "specific");
    	listing().addObjectToPropertyWithKey(aBasic, "basics");

    	ec.saveChanges();

    	return context().page();
    }

public void setListing(Listing newListing) {
listing = newListing;
}
}
Listing has a 'to-one' relationship with Basic and a 'to-one' relationship with Specific. Basic has a 'to-many' relationship with Listing and Specific also has a 'to-many' relationship to Listing. The lists in the WOPopUpButtons work correctly, but I want to set their selected values to the new Listing instance. I assumed that addObjectToBothSidesOfRelationshipWithKey() would add an instance to the Basic side of the relationship which I didn't want. I tried replacing addObjectToPropertyWithKey() meathod with the ones given to me in _Listing.java by EOGenerator. I got "com.webobjects.foundation.NSValidation$ValidationException: The listingType property of Basic is not allowed to be null." which I took to mean that it tried to create and inserted an instance of Basic to go along with the new instance of Listing. That is why I went with addObjectToPropertyWithKey() so that it would take the selected object from the WOPopUpButton list and add it to the Listing instance through the relationship. I now understand that my previous assumptions were very wrong. Can the selection binding actually be tied to the relationship name in the Listing instance?


Thanks for the patience with me,
Awbrey
On Oct 2, 2008, at 12:23 PM, Guido Neitzer wrote:

On 2-Oct-08, at 10:55 AM, David LeBer wrote:

On 2-Oct-08, at 12:46 PM, Guido Neitzer wrote:

On 2-Oct-08, at 10:37 AM, Awbrey Hughlett wrote:

The Basic and Specific EOs are linked to WOPopUpButtons. I want the selection value (bound to aBasic and aSpecific) to be added to the new instance of a Listing EO. I figured I didn't want a new object on both sides of the relationship since aBasic and aSpecific already have values set by the WOPopUpButton. That is why I went with listing().addObjectToPropertyWithKey(aSpecific, "specific"). Is my understanding of this wrong?

Ouch. Yes.

Bind the list to the array of Basic objects, the value to aBasic (DON'T create an instance for that!!!), and the selection to listing.basic. That should "just work".

Guido,

You meant bind 'item' to aBasic right?

Aeh, yes. Obviously.

And is the relationship to Basic from Listing to-one or to-many, the name 'basics' seems to imply a to many.

Sounds like it. So that won't work either. That's why I said we need more input. Letting us play a guessing game isn't really helpful.


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

_______________________________________________ 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

;david

--
David LeBer
Codeferous Software
'co-def-er-ous' adj. Literally 'code-bearing'
site: 	http://codeferous.com
blog: 	http://davidleber.net
profile:	http://www.linkedin.com/in/davidleber
twitter:	http://twitter.com/rebeld
--
Toronto Area Cocoa / WebObjects developers group:
http://tacow.org




_______________________________________________ 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: ClassCastException???
  • Next by Date: WebObjects Training in November
  • Previous by thread: Re: ClassCastException???
  • Next by thread: Ajax loading with subcomponents
  • Index(es):
    • Date
    • Thread