Re: Newbie: Tapestry 2.4 and cayenne1.0a6

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Thu Mar 06 2003 - 18:59:53 EST

  • Next message: Andrus Adamchik: "Re: Key generator question"

    Hi Reinier,

    In the code snip you sent I can't see where you actually create a new
    Store object. I suspect you may create (or rather register) it twice
    somehow. Please send this piece of code.

    In any event, whenever you create an object, it is much cleaner to use the
    code like this (if you don't yet):

      Store store = (Store)ctxt.createAndRegisterNewObject("Store");

    This should be enough to both create an instance and register it with
    DataContext (just like the name of the name of the method implies). There
    is no need to register the object after that, later TRANSIENT check is
    redundant.

    Andrus

    > Okay, the answer night be in the mailing list, but if so I could not
    > recognise it with my limited knowledge.
    >
    > The problem is: I'm trying to take the Cayenne-Tapestry tutorial, and
    > adding an edit page to it. I've modelled a new Store class on the
    > BrowseArtistPage class, and that works very well. Then I added a new
    > editStoreLink (as an ActionLink) that calls the AddStorePage (modelled
    > on AddArtistPage), like so:
    >
    > public void editStoreAction(IRequestCycle cycle) {
    > AddStorePage nextPage = (AddStorePage) cycle.getPage("AddStorePage");
    >
    > nextPage.setStore(store);
    >
    > cycle.setPage(nextPage);
    > }
    >
    > This sets up the AddStorePage with the correct values when it opens, and
    > you can edit them as you like. I commit the changes as follows:
    >
    > public void saveStoreAction(IRequestCycle cycle) {
    > Visit visit = (Visit) this.getPage().getVisit();
    > DataContext ctxt = visit.getDataContext();
    >
    > if (!assertNotNull(store.getName()) ) {
    > appendHtmlToErrorMessage("You must provide a name.");
    > }
    >
    > if (getHasErrorMessage()) return;
    >
    > if (store.getPersistenceState() == PersistenceState.TRANSIENT) {
    > ctxt.registerNewObject(store);
    > }
    >
    > // commit to the database
    > ctxt.commitChanges();
    >
    > BrowseStoresPage nextPage =
    > (BrowseStoresPage) cycle.getPage("BrowseStoresPage");
    >
    > cycle.setPage(nextPage);
    > }
    >
    > I check for the PersistenceState so that an existing object does not get
    > registered again. The idea is that the same page can be used to create
    > and register new objects, as well as edit (without registering) existing
    > objects. However, when I commit the changes, I get a duplicate entry
    > with a new ObjectId.
    >
    > Clearly, I'm still not quite getting something. Please help . . .
    >
    > reinier
    >
    > PS this looks to be a VERY nice combination for developing web apps - I
    > think it will work very well when I understand it a bit better.



    This archive was generated by hypermail 2.0.0 : Thu Mar 06 2003 - 18:59:53 EST