Re: DirectAction to a Primary Key
Re: DirectAction to a Primary Key
- Subject: Re: DirectAction to a Primary Key
- From: Dev WO <email@hidden>
- Date: Wed, 12 Oct 2005 10:21:41 +0200
Hi Will,
I followed David's tip which was pretty close to this one except that
I could handle the exception directly in the try/catch bloc instead
of a separate part using newsitem=null.
In fact I'm just returning the list of the latest news headline if
there's an exception, which is pretty basic but works the way I need
it to for now;)
Thanks again for your support Will:)
Xavier
Hi Xavier
Well, the only way to check if "x" is a valid ID that comes to my
mind is fetching for EO with that ID - and that's exactly what
you're doing. So yes, you'll need to check if newsItem is null. The
docs say, that objectWithPrimaryKey will throw an exception unless
exactly one object is retrieved - but I'm not sure it actually
does, since the docs do not say what kind of exception. So to be
sure I guess what you sould do is something like this:
EOEnterpriseObject newsItem;
try {
NSMutableDictionary keyDict = new NSMutableDictionary();
keyDict.setObjectForKey(id, "newsID"); // let's assume your
news item id field is called "newsID"
newsItem = EOUtilities.objectWithPrimaryKey
(EOSharedEditingContext.defaultSharedEditingContext(), "News",
keyDict);
} catch (Exception e) {
// just to be sure...
newsItem = null;
}
// now test if you've fond a news item
if (newsItem != null) {
// do whatever you want with it - I guess you want to display it
} else {
// probably you want to display an error message
}
Hope this helps.
Cheers,
Will
On 11.10.2005, at 18:01, Dev WO wrote:
Hi Will,
thank you for your sample, it works as expected:)
Just one more thing (no I'm not going to annonce anything;)), if I
wanted to check for a valid newsID, like making sure there's an
item with the specific newsID, should I test it before the
EOEnterpriseObject newsItem = EOUtilities.objectWithPrimaryKey
(EOSharedEditingContext.defaultSharedEditingContext(), "News",
keyDict);
or should I check if newsItem is null? I think the later won't
work as EOUtilities will return an error before the following
lines are executed.
So assuming I'm going for the validation before EOUtilities, I'm
not very familiar with the try/catch stuff, but is it what I
should do?
Thanks a lot again.
Xavier
If I understood you correctly, you would like to have a direct
action to a news detail page displaying the news for ID "x".
In your detail component add a method
public void setNewsItemForID(Integer id) {
NSMutableDictionary keyDict = new NSMutableDictionary();
keyDict.setObjectForKey(id, "newsID"); // let's assume
your news item id field is called "newsID"
EOEnterpriseObject newsItem = EOUtilities.objectWithPrimaryKey
(EOSharedEditingContext.defaultSharedEditingContext(), "News",
keyDict);
// ... and so on
}
Hope this helps.
Cheers,
Will
On 11.10.2005, at 15:59, Dev WO wrote:
Hi list,
I'm actually working on a small "news headline" application.
I have a component with the last x items displayed in list view,
then clicking on one displays this one with all its details.
I need some external pages to be able to provide a link to a
specific item and provide my component with the detailed view
directly.
I think I'll be able to change the conditional value in the
direct action using
nextpage.setConditionnal(new Boolean(true))
but I don't know how to get the correct item using it's primary
key...
After some searching, I have found the following method
EOUtilities.primaryKeyForObject
but I couldn't make this DA works:(
I know it is something trivial I should know about, but I don't;)
So if anyone has a pointer or even better a short sample, It
would help me a lot:)
Thanks
Xavier
_______________________________________________
WebObjects-dev mailing list
email@hidden
http://www.omnigroup.com/mailman/listinfo/webobjects-dev
_______________________________________________
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