Re: Question about fetching
Re: Question about fetching
- Subject: Re: Question about fetching
- From: Chuck Hill <email@hidden>
- Date: Tue, 21 Jul 2009 07:46:46 -0700
On Jul 21, 2009, at 7:22 AM, Francesco Romano wrote:
On 21/lug/09, at 16:16, Chuck Hill wrote:
On Jul 21, 2009, at 6:57 AM, Francesco Romano wrote:
I want to say that this is the first time I do something dynamic
for the web (like an e-commerce site, or a web app) and it's not
my job.. I'm a student and I'm doing a favor to my father...
So... I'm open to every advices, even not related to WO.
Now, my ideas (maybe I've already written this..) is to use direct
actions (well.. stateless component, not using a session, etc)
until a customer add a product to a cart. In that moment the
session is created and saves the products/quantity. When a
customer want to checkout the order he must login, passing to a
https page, etc... (It's a bit far right now... First I've to
finish the "presentation" part..).
So.. that was my idea.. but... due to my inexperience it can be
wrong. (completely or partially).
So.. from what you write to me I've to doubts:
1) During the "presentation" part I don't want/need a session.. so
I use direct actions.
This is an example URL:
.../PNStore.woa/wa/listProducts?merceologia=7
Is it wrong to pass a pk in the URL?
A lot of people have religious objections to this. In most cases
the danger is more theoretical than practical. You have to
decide. Can all customers see all products? What if someone
changes the URL to .../PNStore.woa/wa/listProducts?
merceologia=7000000000, what will your application do? What if
they change it to .../PNStore.woa/wa/listProducts?merceologia=18,
can they see a product they should not?
Well.. I don't know.. I should manage this.. displaying an error
page.. maybe..
You can choose, as long as you are aware that it can happen and handle
it.
(right now I don't know if I'll use an custom identifier for my
products.. maybe I will (it's better) but I've to talk with my
father to decide the format... So.. maybe is better to pass this
ProductID and fetch it?
That still leaves you with much the same problems as above.
Ok.. so.. can I pass through POST instead of GET?
But I lost the bookmarking option..
I'd use GET. You can use POST, but why?
2) The "cart system"
Now I don't save the cart... So if the session expires, you don't
have the cart saved...
Do you think I've to save it?
And.. if yes.. I don't understand how.. Well.. for registered
customer I can save in the db, but for anonymous? I'd like that
someone could choose the products and only before paying login...
You need to use cookies. You could save it in the db with a unique
key that you create and set a cookie with that key into their
browser.
I think I'll postpone this problem.. or it's something that will
force me to re-implements everything?
I think leaving it for later is a good idea.
Chuck
On 21/lug/09, at 15:26, Christian Trotobas wrote:
On 21 juil. 2009, at 15:19, Francesco Romano wrote:
On 21/lug/09, at 12:43, Christian Trotobas wrote:
On 21 juil. 2009, at 12:19, Francesco Romano wrote:
Thanks to both.
I read that chapter in the Apple documentation.
If I understand correctly the globalID has its scope in the
editingcontext.
I don't know why but I create a new editing context for each
page... so this is bad. Should I keep a single editing
context? (until a customer add the first product in the cart I
don't have a session.., so I don't have access to
session().defaultEditingContext()).
Take a look at EOSharedEditingContext. Seems to me this is what
you are looking for.
http://devworld.apple.com/documentation/InternetWeb/Reference/WO542Reference/com/webobjects/eocontrol/EOSharedEditingContext.html
Search the mailing list for EOSharedEditingContext, too.
Ok.. I read that.
For every read-only fetch I changed
ERXEC.newEditingContext()
with
EOSharedEditingContext.defaultSharedEditingContext();
Except this problem, I can do this: (?)
Number pk = product.primaryKey(); //it's a string.. I'll cast
to number
EOEditingContext ec = ERXEC.newEditingContext()
EOEntity entity =
EOModelGroup.defaultGroup().entityNamed("Product");
EOGlobalID gid = entity.globalIDForRow(new
NSDictionary(pk,"id"));
Product p = (product) ec.faultForGlobalID(gid);
Looks good. But Andrew's advice was more an example on how
things work, rather than an advise on what exactly your code
should look like.
Use a shareEditingContext for Products, then a simple
defaultEditingEditing from your Session to store the cart.
Christian
I don't understand " then a simple defaultEditingEditing from
your Session to store the cart."
I thought to use a simple NSMutableArray in the session.
Well... that could work, but you ought to go the EOF way. And it
is something like having an EO to store your customer, then have
another EO to store the cart, then other EO to store the fact
that a Product is in the cart.
Something like :
Customer <-->> Cart ->> Lines -> Product
All but Product "belong" to an editingContext in the Session, aka
the defaultEditingContext to make it simple.
Lines could store the quantity, the price, etc, etc.
Christian
Francesco
Thanks
Francesco
Hello Francesco;
You can construct an EOGlobalID from the primary key an fault
it. I would generally not advocate using the primary key in
this manner as it may be volatile owing to migration of
schema or database product migration. That concern aside,
assuming you have a primary key and it has an attribute name
of "id";
Number pk = ???
EOEditingContext ec = ???
EOEntity entity =
EOModelGroup.defaultGroup().entityNamed("FooBar");
EOGlobalID gid = entity.globalIDForRow(new
NSDictionary(pk,"id"));
FooBar = (FooBar) ec.faultForGlobalID(gid);
Hope this helps.
cheers.
On 21/lug/09, at 11:24, Christian Trotobas wrote:
Hi Francesco
On 21 juil. 2009, at 09:56, Francesco Romano wrote:
Hi..
This is a simple (and maybe stupid) question.
No question is stupid on this list. Feel free to ask.
I'm doing an application (an e-commerce application.. maybe
wo is not the best choice, but I know java better than
ruby..), and I've some pages accessed with directaction.
WebObjects is a pretty good choice for ecommerce; take a look
at the Apple Store to be sure :)
Maybe I'm wrong, but I can pass values to a page only with
the url, so.. only strings.
In a page I select an EntityObject and I've to pass to the
other page.
If I can't pass the whole object, I would like to pass the
primary key, so fetching should be faster..
But.. I can get the key, but I can't fetch an Object with
it's PK.
Now i pass a name (a description string..).. but it's not
unique, so even with low probability, there can be
collisions..
You should use a product ID which would be unique, like a
part number for example. It will be usefull too for
accounting purpose, and not only for the app internals. As a
unique key, the PK could be used, but depending on the nature
of your business, you might want to avoid exposing PK on the
web: they should be considered both confidential and subject
to changes for technical reasons (though it is very unlikely
to occur).
In WebObjects, the EOF framework provides a unique identifier
for EO: it is the EOGlobalID. Basically, it is a compound
from the EOEntity name and the PK from the table (out of the
box, it is how it works; for specific reason out of the scope
of your question, it happens that it is not the PK; again, it
is very unlikeky to occur for standard/simple uses, so don't
bother about this, it was just for information purpose).
Therefore, in your app, if you are looking for a unique
identifier for your EO objects, you have to use the
EOGlobalID and not the PK. Understanding how EOF handles the
uniquing of objects is one the keys for your successfull
development with WebObjects.
Take a close look at:
http://developer.apple.com/documentation/Webobjects/Enterprise_Objects/Fetching/Fetching.html#/
/apple_ref/doc/uid/TP30001011-CH206-BADHCCEE
Hope that helps.
Christian Trotobas
What can I do?
Thanks
Francesco Romano
_______________________________________________
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 (Webobjects-
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
_______________________________________________
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
--
Chuck Hill Senior Consultant / VP Development
Learn WO at WOWODC'09 East in Montréal this August!
http://www.wocommunity.org/wowodc09/east
http://arstechnica.com/apple/news/2009/07/webobjects-sliced-from-106but-prognosis-of-death-premature.ars
--
Chuck Hill Senior Consultant / VP Development
Learn WO at WOWODC'09 East in Montréal this August!
http://www.wocommunity.org/wowodc09/east
http://arstechnica.com/apple/news/2009/07/webobjects-sliced-from-106but-prognosis-of-death-premature.ars
_______________________________________________
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