your class must be declared as "public"
On 10/6/06, Daryl Beattie <[EMAIL PROTECTED]> wrote:
Hi Velocity people,
Okay, first off; I tried searching for answers to this, but
the mailing list archive is not searchable (in any way that I could
find), so if this question is a faq, please don't be upset.
I am having trouble getting a value out of a Map. Every time
I try, the reference gets printed out as it is. Even normal methods
don't seem to be functioning consistently.
I have developed a test case to illustrate my problem. The
code may look long but it's pretty simple:
class BO extends BOBase {
// Empty.
}
class BOBase extends DataHolder {
// Empty.
}
class DataHolder extends HashMap<Name, Value> {
public Value getA() {
return this.get(new Name("a")); //$NON-NLS-1$
}
@Override
public Value get(Object key) {
return super.get(new Name(key.toString()));
}
}
class Name {
String name;
public Name(String name) {
this.name = name;
}
@Override
public String toString() {
return name;
}
@Override
public boolean equals(Object a) {
return ((a != null) && (a instanceof Name) &&
a.toString().equals(this.toString()));
}
@Override
public int hashCode() {
return name.hashCode();
}
}
class Value {
String value;
public Value(String value) {
this.value = value;
}
@Override
public String toString() {
return value;
}
}
And when I run velocity I do this:
VelocityContext context = new VelocityContext();
BO test = new BO();
test.put(new Name("a"), new Value("1"));
context.put("bo", test);
Map<Name, Value> test2 = new HashMap<Name, Value>();
test2.put(new Name("a"), new Value("1"));
context.put("bo2", test2);
context.put("a", new Name("a"));
context.put("test", new String("Boo!"));
My template looks like this:
$bo.A
$bo.getA()
$bo.get("a")
$bo2.get($a)
$test
But my output looks like this:
$bo.A
$bo.getA()
$bo.get("a")
1
Boo!
What is going on?
Sincerely,
Daryl.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]