You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Richard Perfect <ri...@rperfect.net> on 2003/11/15 01:15:11 UTC

Re[2]: How to make id = persistent with lookup of transient model property

Hi Paul,

Thanks for that. For the set method I needed to stick a
fireObservedChange() into the set method, but once I did that I didn't
need the following method;

public void pageBeginRender(PageEvent event) {
  System.out.println("*** Got pageBeginRender(), personID = " + getPersonID());
    if(getPerson() == null) {
       setPerson(getPersonService().findByPrimaryKey(getPersonID()));
    }
}

I think what's happening is that the VLib application doesn't
implement either the getPersonID() or the setPersonID() method and
does your suggested setPerson(loadPerson(id)) in the pageBeginRender()
method instead.

PF> public void setPersonId(Integer id)
PF> {
PF>     this.setPerson(loadPerson(id));  // where loadPerson(Integer) 
PF> fetches and loads the Person object from the data store using the 
PF> specified primary key
PF> }


I hadn't thought of the readObject()/writeObject() technique but I
know how that would work. But the problem with that approach is that
it gets complicated if the objects also need to be serialized for RMI
(for example EJBs) because the readObject()/writeObject() methods then
have to know what in what context the serialisation is being done.

I don't mind the specialised get/setPersonID() technique, it doesn't
seem too much of an impact for a small number of signifcant model
objects types per page.

I'm guessing that the external link thingy is more about supporting
bookmarking than specifically involved in this idea of id to model
object mapping.


 - Richard Perfect





Saturday, November 15, 2003, 12:26:19 PM, you wrote:

PF> I'll take a stab at anwsering your questions:

PF> 1.)  It depends on your application.  In general, it is a bad idea to 
PF> store heavy objects in session.    Although, if you must, you might 
PF> consider implementing your own serialization for the object where 
PF> writeObject() writes only the primary key and readObject() fetches and 
PF> loads the object from your data store using the primary key.

PF> 2.)  pageBeginRender() is an event listener.  To subscribe to page 
PF> render events your page should implement the PageRenderListener interface.
PF> Without looking up the Vlib code, I would expect that the transient 
PF> value is retrieved in the personId mutator methods - something like this:

PF> // This is most likely called during a render cycle
PF> public Integer getPersonId()
PF> {
PF>     return this.getPerson().getId();
PF> }

PF> // This is most likely called during a rewind cycle
PF> public void setPersonId(Integer id)
PF> {
PF>     this.setPerson(loadPerson(id));  // where loadPerson(Integer) 
PF> fetches and loads the Person object from the data store using the 
PF> specified primary key
PF> }

PF> 3.)  activateExternalPage() is called by the ExternalService.  The 
PF> requested page must implement the IExternalPage interface.  The external 
PF> service usually triggered via an ExternalLink component.

PF> Hope this helps,

PF> Paul Ferraro

PF> richard wrote:

>>I've figured out how to do some of the basic things like write a
>>search page, link to an edit page, edit and save a model object.
>>
>>But at the moment the model object needs to be a persistent page
>>property and I would like to know how to make the 'id' the persistent
>>page property and have the model object loaded 'just-in-time' when
>>it's needed. This is because the documentation talks about how
>>persistent page properties are stored in the HttpSession and that you
>>should really only store lightweight immutable objects like Strings and
>>Longs rather than model objects like "PersonModel".
>>
>>1. First of all could someone please clarify whether or not it's a good
>>idea to avoid making 'heavy' mutable objects persistent page
>>properties? - I realise it probably depends on how heavy the heavy
>>objects are, but I'm sort of thinking 100's of users and dozen's of
>>pages so I am a little worried about the memory aspects of storing too
>>much in the HttpSession.
>>
>>
>>2. And if so, how? I see in the Vlib application that it has something
>>similar to what I'm thinking of with the personID being persistent and
>>the person object being transient;
>>
>><property-specification name="personId" type="java.lang.Integer" persistent="yes"/>
>><property-specification name="person" type="org.apache.tapestry.vlib.ejb.Person"/>
>>
>>But I don't understand how and when the pageBeginRender() method gets
>>called. When I try to write my own pageBeginRender() method it doesn't
>>get called.
>>
>>3. Also on the Vlib application there's also a method
>>activateExternalPage() that is involved with the personID's but I
>>don't understand how this method gets called or why it's needed.
>>
>>
>>
>> - Richard Perfect.
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>>
>>  
>>



PF> ---------------------------------------------------------------------
PF> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
PF> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org