You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by wong wayne <wa...@yahoo.com> on 2007/07/16 06:29:20 UTC

Problem when accessing data member

Hi all

I'm using spring with velocity to sending email.
Program works fine when those data needed passing in
String type but I cannot access those data member when
passing as an object. 

At servlet, object add into hashmap model and added
into VelocityEngineUtil
Person p1 = new Person();
p1.setFirstName(firstName);
p1.setLastName(lastName);
model.put("person", p1);

String text =
VelocityEngineUtils.mergeTemplateIntoString(velocityEngine,
"../template/" + emailContent, "utf-8", model);

At vm file, ${person.firstName} used but it seems
cannot be access. Email received with exact the same
as vm file. I tried to use person.getFirstName to
access but same result. 

Any hints would be appreciate, thanks a lot.

regards

wayne



       
____________________________________________________________________________________
Building a website is a piece of cake. Yahoo! Small Business gives you all the tools to get online.
http://smallbusiness.yahoo.com/webhosting 

Re: Problem when accessing data member

Posted by wong wayne <wa...@yahoo.com>.
your guess is correct, I haven't declare Person as
public, thanks for your help

regards

wayne
--- Nathan Bubna <nb...@gmail.com> wrote:

> my guess is that either the getFirstName() method or
> else the whole
> Person class are not declared as public.
> 
> Velocity will only give access to public methods in
> public classes.
> 
> On 7/15/07, wong wayne <wa...@yahoo.com> wrote:
> > Hi all
> >
> > I'm using spring with velocity to sending email.
> > Program works fine when those data needed passing
> in
> > String type but I cannot access those data member
> when
> > passing as an object.
> >
> > At servlet, object add into hashmap model and
> added
> > into VelocityEngineUtil
> > Person p1 = new Person();
> > p1.setFirstName(firstName);
> > p1.setLastName(lastName);
> > model.put("person", p1);
> >
> > String text =
> >
>
VelocityEngineUtils.mergeTemplateIntoString(velocityEngine,
> > "../template/" + emailContent, "utf-8", model);
> >
> > At vm file, ${person.firstName} used but it seems
> > cannot be access. Email received with exact the
> same
> > as vm file. I tried to use person.getFirstName to
> > access but same result.
> >
> > Any hints would be appreciate, thanks a lot.
> >
> > regards
> >
> > wayne
> >
> >
> >
> >
> >
>
____________________________________________________________________________________
> > Building a website is a piece of cake. Yahoo!
> Small Business gives you all the tools to get
> online.
> > http://smallbusiness.yahoo.com/webhosting
> > <html>
> > <head>
> > <meta http-equiv="Content-Type"
> content="text/html; charset=UTF-8"/>
> > <title>
> > Email Title
> > </title>
> > </head>
> > <body>
> > <table width="580" border="0" cellspacing="0"
> cellpadding="0">
> > <tr>This is a template email testing</tr>
> > <tr>ÖÐÎÄ·±ów</tr>
> > <tr>ÖÐÎļòÌå</tr>
> > <tr>Below are attributes pass from servlet</tr>
> > <tr>First Name: $firstName</tr>
> > <tr>Middle initial: $middleName</tr>
> > <tr>Last Name: $lastName</tr>
> > <tr>Company: $submittedCompany</tr>
> > <tr>Address: $addline1</tr>
> > <tr>$addline2</tr>
> > <tr>$addline3</tr>
> > <tr>Phone: $phone</tr>
> > #if ($num == 1)
> > <tr>Num equals to One</tr>
> > #end
> > <tr>${person.firstName}</tr>
> > </table>
> > </body>
> > </html>
> >
> >
>
---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> user-unsubscribe@velocity.apache.org
> > For additional commands, e-mail:
> user-help@velocity.apache.org
> >
> 



       
____________________________________________________________________________________
Be a better Heartthrob. Get better relationship answers from someone who knows. Yahoo! Answers - Check it out. 
http://answers.yahoo.com/dir/?link=list&sid=396545433

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


Re: Problem when accessing data member

Posted by Nathan Bubna <nb...@gmail.com>.
my guess is that either the getFirstName() method or else the whole
Person class are not declared as public.

Velocity will only give access to public methods in public classes.

On 7/15/07, wong wayne <wa...@yahoo.com> wrote:
> Hi all
>
> I'm using spring with velocity to sending email.
> Program works fine when those data needed passing in
> String type but I cannot access those data member when
> passing as an object.
>
> At servlet, object add into hashmap model and added
> into VelocityEngineUtil
> Person p1 = new Person();
> p1.setFirstName(firstName);
> p1.setLastName(lastName);
> model.put("person", p1);
>
> String text =
> VelocityEngineUtils.mergeTemplateIntoString(velocityEngine,
> "../template/" + emailContent, "utf-8", model);
>
> At vm file, ${person.firstName} used but it seems
> cannot be access. Email received with exact the same
> as vm file. I tried to use person.getFirstName to
> access but same result.
>
> Any hints would be appreciate, thanks a lot.
>
> regards
>
> wayne
>
>
>
>
> ____________________________________________________________________________________
> Building a website is a piece of cake. Yahoo! Small Business gives you all the tools to get online.
> http://smallbusiness.yahoo.com/webhosting
> <html>
> <head>
> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
> <title>
> Email Title
> </title>
> </head>
> <body>
> <table width="580" border="0" cellspacing="0" cellpadding="0">
> <tr>This is a template email testing</tr>
> <tr>���ķ��w</tr>
> <tr>���ļ���</tr>
> <tr>Below are attributes pass from servlet</tr>
> <tr>First Name: $firstName</tr>
> <tr>Middle initial: $middleName</tr>
> <tr>Last Name: $lastName</tr>
> <tr>Company: $submittedCompany</tr>
> <tr>Address: $addline1</tr>
> <tr>$addline2</tr>
> <tr>$addline3</tr>
> <tr>Phone: $phone</tr>
> #if ($num == 1)
> <tr>Num equals to One</tr>
> #end
> <tr>${person.firstName}</tr>
> </table>
> </body>
> </html>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> For additional commands, e-mail: user-help@velocity.apache.org
>