Newbie: Tapestry 2.4 and cayenne1.0a6

From: Reinier (Linux 2.2.12) ("Reinier)
Date: Thu Mar 06 2003 - 18:43:57 EST

  • Next message: Andrus Adamchik: "Re: Newbie: Tapestry 2.4 and cayenne1.0a6"

    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:47:26 EST