You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Kelvin Tan <ke...@myangel.com> on 2001/07/31 10:37:59 UTC

Composition

Hi,

I'm having a little trouble with Composition here, so hope someone can shed
some light on the issue.

I've a Feature class which contains(amongst others) a reason String and a
Priority object. They are not assigned to any particular object, with only
their references declared.

In the template, if I use

$!feature.reason

nothing is displayed (which is correct). If I assign a value to "reason",
the value is displayed.

However, if I'm use

$!feature.priority or $feature.getPriority() or

#set($priority = $feature.priority)
$!priority

I get a

org.apache.velocity.exception.MethodInvocationException: Invocation of
method 'getPriority' in class Feature threw exception class
java.lang.NullPointerException

Did I miss any steps out which I should've? Would appreciate the help. Am
using Velocity v1.1. Class listings are below. Thanks!

public class Feature
{
 Priority priority;
 String reason;
...
 public String getPriority()
 {
  return priority.getPriority();
 }
}

public class Priority
{
private String state;
 public String getPriority()
 {
  return state;
 }
}


Re: including macro definitions

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
Paul Sorenson wrote:
> 
> Geir - thanks, you also answered my next question, was this capability
> coming.
> The velocimacro.library approach will get me by until then.
> 
> Any tips on when is this capability is likely to become available?
> 

I am working on the VM stuff at the moment, trying to make autoloading
work for libraries so that you don't have to do anything special (like
dump the servlet runner) to get the VM libraries to auto-reload when you
make a change...  I will see what it takes to stuff this in too.  It's
not as trivial as it first appears.

geir

-- 
Geir Magnusson Jr.                           geirm@optonline.net
System and Software Consulting
Developing for the web?  See http://jakarta.apache.org/velocity/
Well done is better than well said - New England Proverb

Re: including macro definitions

Posted by Paul Sorenson <pa...@classware.com.au>.
Geir - thanks, you also answered my next question, was this capability
coming.
The velocimacro.library approach will get me by until then.

Any tips on when is this capability is likely to become available?

Cheers

----- Original Message -----
From: "Geir Magnusson Jr." <ge...@optonline.net>
To: <ve...@jakarta.apache.org>
Sent: Monday, August 13, 2001 9:15 PM
Subject: Re: including macro definitions


> Sort of.  The problem is that #parse() is a runtime thing, and the
> decision about weather #<foo> is a VM is a parse-time thing, so you
> really can't #parse() in a set of VMs right now (it's coming...)
>
> However, the VM system supports having any number of VM libraries that
> will be loaded at startup :
>
> velocimacro.library = lib1.vm, lib2.vm, lib3.vm, etc



Re: including macro definitions

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
Paul Sorenson wrote:
> 
> Would it be true to say that "macros defined inside a file A that is #parsed
> in file B are not available to file B" (regardless of the value of
> velocimacro.permissions.allow.inline.local.scope and )?

Sort of.  The problem is that #parse() is a runtime thing, and the
decision about weather #<foo> is a VM is a parse-time thing, so you
really can't #parse() in a set of VMs right now (it's coming...)

However, the VM system supports having any number of VM libraries that
will be loaded at startup :

velocimacro.library = lib1.vm, lib2.vm, lib3.vm, etc

> 
> I have tried this myself and also dredged through the archive and am
> guessing the answer is yes but it would be nice if that could be confirmed.

:)

geir

-- 
Geir Magnusson Jr.                           geirm@optonline.net
System and Software Consulting
Developing for the web?  See http://jakarta.apache.org/velocity/
Well done is better than well said - New England Proverb

including macro definitions

Posted by Paul Sorenson <pa...@classware.com.au>.
Would it be true to say that "macros defined inside a file A that is #parsed
in file B are not available to file B" (regardless of the value of
velocimacro.permissions.allow.inline.local.scope and )?

I have tried this myself and also dredged through the archive and am
guessing the answer is yes but it would be nice if that could be confirmed.



Re: Composition

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
Did you ever figure this out?

Kelvin Tan wrote:
> 
> Hi,
> 
> I'm having a little trouble with Composition here, so hope someone can shed
> some light on the issue.
> 
> I've a Feature class which contains(amongst others) a reason String and a
> Priority object. They are not assigned to any particular object, with only
> their references declared.
> 
> In the template, if I use
> 
> $!feature.reason
> 
> nothing is displayed (which is correct). If I assign a value to "reason",
> the value is displayed.
> 
> However, if I'm use
> 
> $!feature.priority or $feature.getPriority() or
> 
> #set($priority = $feature.priority)
> $!priority
> 
> I get a
> 
> org.apache.velocity.exception.MethodInvocationException: Invocation of
> method 'getPriority' in class Feature threw exception class
> java.lang.NullPointerException
> 
> Did I miss any steps out which I should've? Would appreciate the help. Am
> using Velocity v1.1. Class listings are below. Thanks!
> 
> public class Feature
> {
>  Priority priority;
>  String reason;
> ...
>  public String getPriority()
>  {
>   return priority.getPriority();
>  }
> }
> 
> public class Priority
> {
> private String state;
>  public String getPriority()
>  {
>   return state;
>  }
> }

-- 
Geir Magnusson Jr.                           geirm@optonline.net
System and Software Consulting
Developing for the web?  See http://jakarta.apache.org/velocity/
Well done is better than well said - New England Proverb

Re: Composition

Posted by Kelvin Tan <ke...@relevanz.com>.
hmmmm...yes you're right. Clearly don't have sufficiently strong concept. I
thought that if you didn't initialize a variable, it'd be void actually.

Thanks anyway...appreciate the pointer.

----- Original Message -----
From: "Jim Seach" <jw...@yahoo.com>
To: <ve...@jakarta.apache.org>
Sent: Tuesday, July 31, 2001 7:39 PM
Subject: Re: Composition


> Shouldn't your feature.getPriority be:
>
>   public String getPriority()
>   {
>    if (priority == null)
>      return null;
>    else
>      return priority.getPriority();
>   }
>
> Jim
>
> --- Kelvin Tan <ke...@myangel.com> wrote:
> > Hi,
> >
> > I'm having a little trouble with Composition here,
> > so hope someone can shed
> > some light on the issue.
> >
> > I've a Feature class which contains(amongst others)
> > a reason String and a
> > Priority object. They are not assigned to any
> > particular object, with only
> > their references declared.
> >
> > In the template, if I use
> >
> > $!feature.reason
> >
> > nothing is displayed (which is correct). If I assign
> > a value to "reason",
> > the value is displayed.
> >
> > However, if I'm use
> >
> > $!feature.priority or $feature.getPriority() or
> >
> > #set($priority = $feature.priority)
> > $!priority
> >
> > I get a
> >
> >
> org.apache.velocity.exception.MethodInvocationException:
> > Invocation of
> > method 'getPriority' in class Feature threw
> > exception class
> > java.lang.NullPointerException
> >
> > Did I miss any steps out which I should've? Would
> > appreciate the help. Am
> > using Velocity v1.1. Class listings are below.
> > Thanks!
> >
> > public class Feature
> > {
> >  Priority priority;
> >  String reason;
> > ...
> >  public String getPriority()
> >  {
> >   return priority.getPriority();
> >  }
> > }
> >
> > public class Priority
> > {
> > private String state;
> >  public String getPriority()
> >  {
> >   return state;
> >  }
> > }
> >
>
>
> __________________________________________________
> Do You Yahoo!?
> Make international calls for as low as $.04/minute with Yahoo! Messenger
> http://phonecard.yahoo.com/
>


Re: Composition

Posted by Jim Seach <jw...@yahoo.com>.
Shouldn't your feature.getPriority be:

  public String getPriority()
  {
   if (priority == null)
     return null;
   else
     return priority.getPriority();
  }

Jim

--- Kelvin Tan <ke...@myangel.com> wrote:
> Hi,
> 
> I'm having a little trouble with Composition here,
> so hope someone can shed
> some light on the issue.
> 
> I've a Feature class which contains(amongst others)
> a reason String and a
> Priority object. They are not assigned to any
> particular object, with only
> their references declared.
> 
> In the template, if I use
> 
> $!feature.reason
> 
> nothing is displayed (which is correct). If I assign
> a value to "reason",
> the value is displayed.
> 
> However, if I'm use
> 
> $!feature.priority or $feature.getPriority() or
> 
> #set($priority = $feature.priority)
> $!priority
> 
> I get a
> 
>
org.apache.velocity.exception.MethodInvocationException:
> Invocation of
> method 'getPriority' in class Feature threw
> exception class
> java.lang.NullPointerException
> 
> Did I miss any steps out which I should've? Would
> appreciate the help. Am
> using Velocity v1.1. Class listings are below.
> Thanks!
> 
> public class Feature
> {
>  Priority priority;
>  String reason;
> ...
>  public String getPriority()
>  {
>   return priority.getPriority();
>  }
> }
> 
> public class Priority
> {
> private String state;
>  public String getPriority()
>  {
>   return state;
>  }
> }
> 


__________________________________________________
Do You Yahoo!?
Make international calls for as low as $.04/minute with Yahoo! Messenger
http://phonecard.yahoo.com/