When to instantiate the Visit object

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

When to instantiate the Visit object

coriolisguy
Hi all,

I have an application where I need to instantiate the
my custom Visit object as early as possible. So, here
is my Home.java object and I get a
NullPointerException
org.apache.tapestry.AbstractPage.getVisit(AbstractPage.java:367)


Am I supposed to instantiate this object somewhere
else or does it matter. the web.xml is also included.

Thanks
E


package com.intaglio.webclient.site;

import org.apache.tapestry.html.*;

public class CHome extends BasePage {
        public CHome() {
                super();
               
                Visit v = (Visit)getVisit();
        }
}



<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app
      PUBLIC "-//Sun Microsystems, Inc.//DTD Web
Application 2.3//EN"
      "http://java.sun.com/dtd/web-app_2_3.dtd">
<!-- generated by Spindle,
http://spindle.sourceforge.net -->


<web-app>
    <display-name>IntaglioWebClient</display-name>
    <filter>
        <filter-name>redirect</filter-name>
       
<filter-class>org.apache.tapestry.RedirectFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>redirect</filter-name>
        <url-pattern>/</url-pattern>
    </filter-mapping>
    <servlet>
        <servlet-name>IntaglioWebClient</servlet-name>
       
<servlet-class>org.apache.tapestry.ApplicationServlet</servlet-class>
        <init-param>
           
<param-name>org.apache.tapestry.visit-class</param-name>
           
<param-value>com.intaglio.webclient.site.Visit</param-value>
        </init-param>
        <load-on-startup>0</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>IntaglioWebClient</servlet-name>
        <url-pattern>/app</url-pattern>
    </servlet-mapping>
</web-app>





---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: When to instantiate the Visit object

Robert Zeigler
A few things to note.
1) Setting the visit in the constructor is a bad idea, since page
instances are pooled.
2) Since pages are pooled, various bits of information needed for a page
at rendering time are not available at creation time.
In this case, the IRequestCycle is null.

You'll want to wait to grab the visit until you're actually rendering
(or rewinding) something.  This will ensure that you grab the /correct/
visit each time.

Robert

Edward Scanzano wrote:

> Hi all,
>
> I have an application where I need to instantiate the
> my custom Visit object as early as possible. So, here
> is my Home.java object and I get a
> NullPointerException
> org.apache.tapestry.AbstractPage.getVisit(AbstractPage.java:367)
>
>
> Am I supposed to instantiate this object somewhere
> else or does it matter. the web.xml is also included.
>
> Thanks
> E
>
>
> package com.intaglio.webclient.site;
>
> import org.apache.tapestry.html.*;
>
> public class CHome extends BasePage {
> public CHome() {
> super();
>
> Visit v = (Visit)getVisit();
> }
> }
>
>
>
> <?xml version="1.0" encoding="UTF-8"?>
> <!DOCTYPE web-app
>       PUBLIC "-//Sun Microsystems, Inc.//DTD Web
> Application 2.3//EN"
>       "http://java.sun.com/dtd/web-app_2_3.dtd">
> <!-- generated by Spindle,
> http://spindle.sourceforge.net -->
>
>
> <web-app>
>     <display-name>IntaglioWebClient</display-name>
>     <filter>
>         <filter-name>redirect</filter-name>
>        
> <filter-class>org.apache.tapestry.RedirectFilter</filter-class>
>     </filter>
>     <filter-mapping>
>         <filter-name>redirect</filter-name>
>         <url-pattern>/</url-pattern>
>     </filter-mapping>
>     <servlet>
>         <servlet-name>IntaglioWebClient</servlet-name>
>        
> <servlet-class>org.apache.tapestry.ApplicationServlet</servlet-class>
>         <init-param>
>            
> <param-name>org.apache.tapestry.visit-class</param-name>
>            
> <param-value>com.intaglio.webclient.site.Visit</param-value>
>         </init-param>
>         <load-on-startup>0</load-on-startup>
>     </servlet>
>     <servlet-mapping>
>         <servlet-name>IntaglioWebClient</servlet-name>
>         <url-pattern>/app</url-pattern>
>     </servlet-mapping>
> </web-app>
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: When to instantiate the Visit object

Ron Piterman
In reply to this post by coriolisguy
Instanciating the visit on your own is a very bad idea...

I think the best you can is calling getVisit() on a life-cycle method -
I am not sure how they are all called: beforeRender or something like
that...
Cheers,
Ron


????? Edward Scanzano:

> Hi all,
>
> I have an application where I need to instantiate the
> my custom Visit object as early as possible. So, here
> is my Home.java object and I get a
> NullPointerException
> org.apache.tapestry.AbstractPage.getVisit(AbstractPage.java:367)
>
>
> Am I supposed to instantiate this object somewhere
> else or does it matter. the web.xml is also included.
>
> Thanks
> E
>
>
> package com.intaglio.webclient.site;
>
> import org.apache.tapestry.html.*;
>
> public class CHome extends BasePage {
> public CHome() {
> super();
>
> Visit v = (Visit)getVisit();
> }
> }
>
>
>
> <?xml version="1.0" encoding="UTF-8"?>
> <!DOCTYPE web-app
>       PUBLIC "-//Sun Microsystems, Inc.//DTD Web
> Application 2.3//EN"
>       "http://java.sun.com/dtd/web-app_2_3.dtd">
> <!-- generated by Spindle,
> http://spindle.sourceforge.net -->
>
>
> <web-app>
>     <display-name>IntaglioWebClient</display-name>
>     <filter>
>         <filter-name>redirect</filter-name>
>        
> <filter-class>org.apache.tapestry.RedirectFilter</filter-class>
>     </filter>
>     <filter-mapping>
>         <filter-name>redirect</filter-name>
>         <url-pattern>/</url-pattern>
>     </filter-mapping>
>     <servlet>
>         <servlet-name>IntaglioWebClient</servlet-name>
>        
> <servlet-class>org.apache.tapestry.ApplicationServlet</servlet-class>
>         <init-param>
>            
> <param-name>org.apache.tapestry.visit-class</param-name>
>            
> <param-value>com.intaglio.webclient.site.Visit</param-value>
>         </init-param>
>         <load-on-startup>0</load-on-startup>
>     </servlet>
>     <servlet-mapping>
>         <servlet-name>IntaglioWebClient</servlet-name>
>         <url-pattern>/app</url-pattern>
>     </servlet-mapping>
> </web-app>
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]