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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]