|
View:
New views
3 Messages
—
Rating Filter:
Alert me
|
|
|
hi, I got some problem in velocity 1.5Null reference [template 'control.vm', line 5, column 10] : $user.name
cannot be resolved. the following is java code: { Template template = Velocity.getTemplate("control.vm", "GBK"); VelocityContext ctx = new VelocityContext(); List l= new ArrayList(); l.add("pp"); l.add("gg"); ctx.put("list",l ); class User{ public String name="mead"; public String pswd="admin"; public String getName() { return name; } public void setName(String name) { this.name = name; } public String getPswd() { return pswd; } public void setPswd(String pswd) { this.pswd = pswd; } } User user = new User(); ctx.put("user",user); this.print(user.name); FileOutputStream fos = new FileOutputStream(Config.ACTION_Path+"TestControl.java"); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(fos)); template.merge(ctx, writer); writer.flush(); writer.close(); fos.close(); } ######################################## here is the Velocity Template ## It is ok,and the list can iterator ok ${title} ## It is null reference $user.name ${user.name} $user.getName() ${user.getName()} ###################### I really dont know the issue. I think the code and template syntax is ok. --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@... For additional commands, e-mail: user-help@... |
|
|
Re: hi, I got some problem in velocity 1.5Hi,
try using "public class User ...". I suspect velocity fails to introspect non-public classes. Regards, Christoph Mead Lai wrote: > Null reference [template 'control.vm', line 5, column 10] : $user.name > cannot be resolved. > > the following is java code: > { > Template template = Velocity.getTemplate("control.vm", "GBK"); > VelocityContext ctx = new VelocityContext(); > > List l= new ArrayList(); > l.add("pp"); > l.add("gg"); > ctx.put("list",l ); > class User{ > public String name="mead"; > public String pswd="admin"; > public String getName() { > return name; > } > public void setName(String name) { > this.name = name; > } > public String getPswd() { > return pswd; > } > public void setPswd(String pswd) { > this.pswd = pswd; > } > } > User user = new User(); > ctx.put("user",user); > this.print(user.name); > FileOutputStream fos = new > FileOutputStream(Config.ACTION_Path+"TestControl.java"); > BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(fos)); > template.merge(ctx, writer); > writer.flush(); > writer.close(); > fos.close(); > } > > ######################################## > here is the Velocity Template > ## It is ok,and the list can iterator ok > ${title} > ## It is null reference > $user.name > ${user.name} > $user.getName() > ${user.getName()} > ###################### > > I really dont know the issue. I think the code and template syntax is ok. > > --------------------------------------------------------------------- > To unsubscribe, e-mail: user-unsubscribe@... > For additional commands, e-mail: user-help@... > > --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@... For additional commands, e-mail: user-help@... |
|
|
Re: hi, I got some problem in velocity 1.5That's true, your classes/methods have to be public. I'm not sure if is
possible right now, but it will be useful to have one warning per class/method in such cases. The logging level should be adjustable, sometime it is useful to log them as errors so you will know when they fail during test unit. For example : you can have a public class and somebody decides it can be private without knowing it is referenced in a template(the code compiles just fine). The application is deployed and it won't work as expected.You will look for hours until you will realize the real cause. apache@... wrote: > Hi, > > try using "public class User ...". I suspect velocity fails to > introspect non-public classes. > > Regards, > Christoph > > Mead Lai wrote: >> Null reference [template 'control.vm', line 5, column 10] : $user.name >> cannot be resolved. >> >> the following is java code: >> { >> Template template = Velocity.getTemplate("control.vm", "GBK"); >> VelocityContext ctx = new VelocityContext(); >> >> List l= new ArrayList(); >> l.add("pp"); >> l.add("gg"); >> ctx.put("list",l ); >> class User{ >> public String name="mead"; >> public String pswd="admin"; >> public String getName() { >> return name; >> } >> public void setName(String name) { >> this.name = name; >> } >> public String getPswd() { >> return pswd; >> } >> public void setPswd(String pswd) { >> this.pswd = pswd; >> } >> } >> User user = new User(); >> ctx.put("user",user); >> this.print(user.name); >> FileOutputStream fos = new >> FileOutputStream(Config.ACTION_Path+"TestControl.java"); >> BufferedWriter writer = new BufferedWriter(new >> OutputStreamWriter(fos)); >> template.merge(ctx, writer); >> writer.flush(); >> writer.close(); >> fos.close(); >> } >> >> ######################################## >> here is the Velocity Template >> ## It is ok,and the list can iterator ok >> ${title} >> ## It is null reference >> $user.name >> ${user.name} >> $user.getName() >> ${user.getName()} >> ###################### >> >> I really dont know the issue. I think the code and template syntax is >> ok. >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: user-unsubscribe@... >> For additional commands, e-mail: user-help@... >> >> > > --------------------------------------------------------------------- > To unsubscribe, e-mail: user-unsubscribe@... > For additional commands, e-mail: user-help@... > --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@... For additional commands, e-mail: user-help@... |
| Free Forum Powered by Nabble | Forum Help |