You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Patrick Moore <pm...@yahoo.com> on 2006/08/11 22:14:09 UTC

canonical way to add behavior?

Hi there -

I think this is one of those questions that "everyone-knows-the-answer" so no
one documents the answer for those who don't!

The problem:

I want to create a BroadcastMessage to hold entered information. Until the user
successfully submits the page, the page needs to work on the same object.
However, as per the documentation, using @InitialValue will result in 1 extra
call to 'getNewEnvelope'. It also leaves a BroadcastMessage attached to the
page which will cause a memory leak.

The suggestion of doing this initialization in finishLoad() does not work for
my case because the BroadcastMessageEntry component is passed a reference to
the created BroadcastMessage and finishLoad() runs too late. 

I looked at using pageBeginRender but that has the opposite problem of seeming
to run too early, before the values in the page are set. Also this solution has
issues when the page is reloaded, or the back button is used.

Thanks 

-Pat
code snippet: 


public abstract class BroadcastMessageEntryPage extends BasePage {
    @InjectState("userInformation")
    public abstract Session getSession();
    @Component(type="BroadcastMessageEntry", 
            bindings = {"broadcastEnvelope=broadcastEnvelope"})
    public abstract BroadcastMessageEntry getBroadcastMessageEntry();

    @Persist @InitialValue("newEnvelope") 
    public abstract BroadcastEnvelope getBroadcastEnvelope();
    public abstract void setBroadcastEnvelope(BroadcastEnvelope
broadcastEnvelope);
    
    public synchronized BroadcastEnvelope getNewEnvelope() {
        BroadcastEnvelope broadcastEnvelope = ... make new message ...
        return broadcastEnvelope;
    }
    public void createNewBroadcastMessage() {
        // .... process message 
        // once submitted make sure that if the user uses the back button on
the 
        // browser that the same BroadcastEnvelope is not reused.
        setBroadcastEnvelope(getNewEnvelope());
    }

}

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