You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by SWC <ma...@crissman.net> on 2004/02/16 18:22:18 UTC

DirectLink (in Enhanced Class?) Issue

Having some trouble with a DirectLink, and it seems like maybe it is  
related to how classes get enhanced, but I'm certainly not confident of  
that.

I have a direct link in a component, that in turn calls a method in its  
controller. The controller is specified as a property of the component.  
I initially had this set up as an action link, and the process worked  
fine. After setting it up as a direct link, however, I receive a null  
pointer exception error. I've added a bunch of dummy code to verify  
that the controller is not null, and it (literally) seems impossible,  
yet I get the error all the same. Anyone have any idea what is occuring  
here?

Again, if I bind to an ActionLink instead of a DirectLink, I see no  
error at all.

The (possibly) relevant details:
   - Tapestry 3.0b2
   - Tomcat 4.1.24

Here is the method that gets called (ie, bound to the listener property  
of the DirectLink):
    public void onViewRecord( IRequestCycle cycle )
    {         
         IPortalController ipc = getController();
        
        if ( ipc == null )
        {
            IBinding binding = getBinding("controller");             
             if ( binding.getObject() == null) {
                System.out.println( "Null controller not allowed!" );
            }
            else             
             {
                setController( (IPortalController)binding.getObject());
            }
        }
        
        System.out.println( "Found controller: " );
        System.out.flush();
        try {
            ipc.onViewRecord( getIdentifier(), cycle );
        }
        catch (Exception e) { e.printStackTrace(); }
    }


This is the ipc.onViewRecord( String, IRequestCycle ) method (nothing  
fancy here...):
    public void onViewRecord(String identifier, IRequestCycle cycle)
    {
        System.out.println( "Viewing Record" );
        System.out.flush();
    }


And here is the output from a run:
Found controller:
java.lang.NullPointerException
        at com.pti.components.Portal.onViewRecord(Portal.java:84)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at  
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.jav 
a:39)
        at  
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessor 
Impl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:324)
        at  
org.apache.tapestry.listener.ListenerMap.invokeTargetMethod(ListenerMap. 
java:301)
        at  
org.apache.tapestry.listener.ListenerMap.access$100(ListenerMap.java: 
87)
        at  
org.apache.tapestry.listener.ListenerMap$SyntheticListener.invoke(Listen 
erMap.java:141)
        at  
org.apache.tapestry.listener.ListenerMap$SyntheticListener.actionTrigger 
ed(ListenerMap.java:146)
        at  
org.apache.tapestry.link.DirectLink.trigger(DirectLink.java:160)
        at  
org.apache.tapestry.engine.DirectService.service(DirectService.java: 
203)
        at  
org.apache.tapestry.engine.AbstractEngine.service(AbstractEngine.java: 
913)
        at  
org.apache.tapestry.ApplicationServlet.doService(ApplicationServlet.java 
:238)
        at  
org.apache.tapestry.ApplicationServlet.doGet(ApplicationServlet.java: 
199)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)





RE: DirectLink (in Enhanced Class?) Issue

Posted by "Howard M. Lewis Ship" <hl...@comcast.net>.
I suspect you've hit the "dirty laundry" of Tapestry: parameter directions. If you use direction
"in" on your component parameters, then the values for those parameters are only valid when the
component is rendering ... not inside a listener method. You need to use direction "auto", which is
less efficient (more OGNL, more reflection) but works from a listener method.

This area is due for some re-architecting in release 3.1.

--
Howard M. Lewis Ship
Independent J2EE / Open-Source Java Consultant
Creator, Tapestry: Java Web Components 
http://howardlewisship.com


> -----Original Message-----
> From: SWC [mailto:mail@crissman.net] 
> Sent: Monday, February 16, 2004 12:22 PM
> To: Tapestry users
> Subject: DirectLink (in Enhanced Class?) Issue
> 
> 
> Having some trouble with a DirectLink, and it seems like maybe it is  
> related to how classes get enhanced, but I'm certainly not 
> confident of  
> that.
> 
> I have a direct link in a component, that in turn calls a 
> method in its  
> controller. The controller is specified as a property of the 
> component.  
> I initially had this set up as an action link, and the 
> process worked  
> fine. After setting it up as a direct link, however, I 
> receive a null  
> pointer exception error. I've added a bunch of dummy code to verify  
> that the controller is not null, and it (literally) seems 
> impossible,  
> yet I get the error all the same. Anyone have any idea what 
> is occuring  
> here?
> 
> Again, if I bind to an ActionLink instead of a DirectLink, I see no  
> error at all.
> 
> The (possibly) relevant details:
>    - Tapestry 3.0b2
>    - Tomcat 4.1.24
> 
> Here is the method that gets called (ie, bound to the 
> listener property  
> of the DirectLink):
>     public void onViewRecord( IRequestCycle cycle )
>     {         
>          IPortalController ipc = getController();
>         
>         if ( ipc == null )
>         {
>             IBinding binding = getBinding("controller");             
>              if ( binding.getObject() == null) {
>                 System.out.println( "Null controller not allowed!" );
>             }
>             else             
>              {
>                 setController( 
> (IPortalController)binding.getObject());
>             }
>         }
>         
>         System.out.println( "Found controller: " );
>         System.out.flush();
>         try {
>             ipc.onViewRecord( getIdentifier(), cycle );
>         }
>         catch (Exception e) { e.printStackTrace(); }
>     }
> 
> 
> This is the ipc.onViewRecord( String, IRequestCycle ) method 
> (nothing  
> fancy here...):
>     public void onViewRecord(String identifier, IRequestCycle cycle)
>     {
>         System.out.println( "Viewing Record" );
>         System.out.flush();
>     }
> 
> 
> And here is the output from a run:
> Found controller:
> java.lang.NullPointerException
>         at com.pti.components.Portal.onViewRecord(Portal.java:84)
>         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>         at  
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccess
> orImpl.jav 
> a:39)
>         at  
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMeth
> odAccessor 
> Impl.java:25)
>         at java.lang.reflect.Method.invoke(Method.java:324)
>         at  
> org.apache.tapestry.listener.ListenerMap.invokeTargetMethod(Li
> stenerMap. 
> java:301)
>         at  
> org.apache.tapestry.listener.ListenerMap.access$100(ListenerMap.java: 
> 87)
>         at  
> org.apache.tapestry.listener.ListenerMap$SyntheticListener.inv
> oke(Listen 
> erMap.java:141)
>         at  
> org.apache.tapestry.listener.ListenerMap$SyntheticListener.act
> ionTrigger 
> ed(ListenerMap.java:146)
>         at  
> org.apache.tapestry.link.DirectLink.trigger(DirectLink.java:160)
>         at  
> org.apache.tapestry.engine.DirectService.service(DirectService.java: 
> 203)
>         at  
> org.apache.tapestry.engine.AbstractEngine.service(AbstractEngi
> ne.java: 
> 913)
>         at  
> org.apache.tapestry.ApplicationServlet.doService(ApplicationSe
> rvlet.java 
> :238)
>         at  
> org.apache.tapestry.ApplicationServlet.doGet(ApplicationServlet.java: 
> 199)
>         at 
> javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
> 
> 
> 
> 
> 


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


Re: DirectLink (in Enhanced Class?) Issue

Posted by SWC <ma...@crissman.net>.
Argh, I hate it when something obvious hits me like that.  Thanks for 
saving a tiny portion of my sanity.

Alright, that takes care of the implementation problem, but I still do 
not understand why I can use the ActionLinks without having to 
check/set the binding to the controller, when in all cases the beinding 
has to be set for the DirectLinks manually.  When do the bindings get 
set, and why is it different for different links?  Shouldn't the 
binding values have been pulled for all components by the time the page 
renders?  That doesn't seem to be the case, but I'm still confused as 
to why.

Spencer


On Feb 16, 2004, at 2:07 PM, Petter Måhlén wrote:

> Isn't it just the case that if (ipc == null), it will never get 
> changed to
> anything else? Meaning that the ipc.onViewRecord() call will throw a
> NullPointerException? What if you add the line below:
>
>>     public void onViewRecord( IRequestCycle cycle )
>>     {         
>>          IPortalController ipc = getController();
>>         
>>         if ( ipc == null )
>>         {
>>             IBinding binding = getBinding("controller");             
>>              if ( binding.getObject() == null) {
>>                 System.out.println( "Null controller not allowed!" );
>>             }
>>             else             
>>              {
>>                 setController(
>> (IPortalController)binding.getObject());
>
> ipc = getController();
>
>>             }
>>         }
>>         
>>         System.out.println( "Found controller: " );
>>         System.out.flush();
>>         try {
>>             ipc.onViewRecord( getIdentifier(), cycle );
>>         }
>>         catch (Exception e) { e.printStackTrace(); }
>>     }
>>


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


RE: DirectLink (in Enhanced Class?) Issue

Posted by Petter Måhlén <pe...@chello.se>.
Isn't it just the case that if (ipc == null), it will never get changed to
anything else? Meaning that the ipc.onViewRecord() call will throw a
NullPointerException? What if you add the line below:

>     public void onViewRecord( IRequestCycle cycle )
>     {         
>          IPortalController ipc = getController();
>         
>         if ( ipc == null )
>         {
>             IBinding binding = getBinding("controller");             
>              if ( binding.getObject() == null) {
>                 System.out.println( "Null controller not allowed!" );
>             }
>             else             
>              {
>                 setController( 
> (IPortalController)binding.getObject());

ipc = getController();

>             }
>         }
>         
>         System.out.println( "Found controller: " );
>         System.out.flush();
>         try {
>             ipc.onViewRecord( getIdentifier(), cycle );
>         }
>         catch (Exception e) { e.printStackTrace(); }
>     }
>