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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to