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