You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Edward Scanzano <es...@yahoo.com> on 2005/05/12 20:01:15 UTC

When to instantiate the Visit object

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: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: When to instantiate the Visit object

Posted by Ron Piterman <mp...@vollbio.de>.
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: tapestry-user-unsubscribe@jakarta.apache.org
> 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


Re: When to instantiate the Visit object

Posted by Robert Zeigler <ro...@scazdl.org>.
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: tapestry-user-unsubscribe@jakarta.apache.org
> 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