You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Laurent Cornelis <la...@ubiquity.be> on 2003/06/11 17:26:38 UTC

Wich method to initialize page properties ?

Hi,

I have a question (yes, again ;-))

I have a page with a form.

When the page is loaded, I want that the properties of the form (member
variables of the page) synchronize themself with an Object in Visit. If the
Object within Visit is not there, initialize the values with null or a
default value.

I tough initialize method was done for it but I'm not sure ...

Here is my code :

public class MyPage extends BasePage {

   private String _myProperty;

  public String getMyProperty() {
   return _myProperty;
 }

   public void setMyProperty(String prop) {
       _MyProperty = prop;
   }


protected void initialize() {

    // Reset everything
    _myProperty = null;

    // Get Visit object
    MyVisit visit = null;
    MyObject obj = null;

    if (getEngine() != null) {
        visit = (MyVisit) getVisit();
        if (visit != null) {
            //Get my object from visit
            obj = visit.getMyObject();
        }
    }

    //My object is present
    if (obj null) {
        _myProperty = obj.getMyProperty();
    }
    // Else initialize with default value
    else {
      _myProperty = "Default";
    }

    super.initialize();
}

public void validate(IRequestCycle cycle) throws RequestCycleException {
    // Create the visit object
    getVisit();
    super.validate(cycle);
}

public void formSubmit(IRequestCycle cycle) {

    Form form = (Form) getComponent("myForm");

    if (!form.getDelegate().getHasErrors()) {

        MyVisit visit = (MyVisit) getVisit();

        //Get objom visit
        MyObject obj = visit.getMyObject();

        // Set my prpperty
        obj.setMyProperty(getMyProperty());

        cycle.setPage("Next");
    }

}

}



The problem is the page is detached, the page is reinitialized with the
values from my visit ... So others users see it.

What method should I override to properly initialize page properties ?

Regards,

Laurent


Re: Wich method to initialize page properties ?

Posted by Harish Krishnaswamy <hk...@comcast.net>.
What do you mean by  "loaded"? If you mean everytime the page is 
rendered, then initialize is probably not what you want, you may want to 
implement PageRenderListener.pageBeginRender. Initialize, I believe, is 
called only once when the page class is instantiated and not everytime 
the page is attached to the engine.

-Harish

Laurent Cornelis wrote:

>Hi,
>
>I have a question (yes, again ;-))
>
>I have a page with a form.
>
>When the page is loaded, I want that the properties of the form (member
>variables of the page) synchronize themself with an Object in Visit. If the
>Object within Visit is not there, initialize the values with null or a
>default value.
>
>I tough initialize method was done for it but I'm not sure ...
>
>Here is my code :
>
>public class MyPage extends BasePage {
>
>   private String _myProperty;
>
>  public String getMyProperty() {
>   return _myProperty;
> }
>
>   public void setMyProperty(String prop) {
>       _MyProperty = prop;
>   }
>
>
>protected void initialize() {
>
>    // Reset everything
>    _myProperty = null;
>
>    // Get Visit object
>    MyVisit visit = null;
>    MyObject obj = null;
>
>    if (getEngine() != null) {
>        visit = (MyVisit) getVisit();
>        if (visit != null) {
>            //Get my object from visit
>            obj = visit.getMyObject();
>        }
>    }
>
>    //My object is present
>    if (obj null) {
>        _myProperty = obj.getMyProperty();
>    }
>    // Else initialize with default value
>    else {
>      _myProperty = "Default";
>    }
>
>    super.initialize();
>}
>
>public void validate(IRequestCycle cycle) throws RequestCycleException {
>    // Create the visit object
>    getVisit();
>    super.validate(cycle);
>}
>
>public void formSubmit(IRequestCycle cycle) {
>
>    Form form = (Form) getComponent("myForm");
>
>    if (!form.getDelegate().getHasErrors()) {
>
>        MyVisit visit = (MyVisit) getVisit();
>
>        //Get objom visit
>        MyObject obj = visit.getMyObject();
>
>        // Set my prpperty
>        obj.setMyProperty(getMyProperty());
>
>        cycle.setPage("Next");
>    }
>
>}
>
>}
>
>
>
>The problem is the page is detached, the page is reinitialized with the
>values from my visit ... So others users see it.
>
>What method should I override to properly initialize page properties ?
>
>Regards,
>
>Laurent
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>
>  
>