Fixed Templator Super class issue
This commit is contained in:
parent
28a777faae
commit
fdc8c8caf5
3 changed files with 15 additions and 1 deletions
BIN
Zutil.jar
BIN
Zutil.jar
Binary file not shown.
|
|
@ -394,7 +394,7 @@ public class Templator {
|
||||||
else {
|
else {
|
||||||
// Using a loop as the direct lookup throws a exception if no field was found
|
// Using a loop as the direct lookup throws a exception if no field was found
|
||||||
// So this is probably a bit faster
|
// So this is probably a bit faster
|
||||||
for (Field field : obj.getClass().getDeclaredFields()) { // Only look for public fields
|
for (Field field : obj.getClass().getFields()) { // Only look for public fields
|
||||||
if (field.getName().equals(attrib)) {
|
if (field.getName().equals(attrib)) {
|
||||||
field.setAccessible(true);
|
field.setAccessible(true);
|
||||||
return field.get(obj);
|
return field.get(obj);
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,9 @@ public class TemplatorTest {
|
||||||
class TestClass{
|
class TestClass{
|
||||||
public String attr;
|
public String attr;
|
||||||
}
|
}
|
||||||
|
class TestSubClass extends TestClass{
|
||||||
|
public String subAttr;
|
||||||
|
}
|
||||||
class TestFuncClass{
|
class TestFuncClass{
|
||||||
public boolean isTrue(){
|
public boolean isTrue(){
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -287,4 +290,15 @@ public class TemplatorTest {
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"<HTML>super:sub1,sub2</HTML>", tmpl.compile());
|
"<HTML>super:sub1,sub2</HTML>", tmpl.compile());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void subClassTest(){
|
||||||
|
Templator tmpl = new Templator("<HTML>{{test.attr}}:{{test.subAttr}}</HTML>");
|
||||||
|
TestSubClass obj = new TestSubClass();
|
||||||
|
obj.attr = "1234";
|
||||||
|
obj.subAttr = "5678";
|
||||||
|
tmpl.set("test", obj);
|
||||||
|
assertEquals("<HTML>1234:5678</HTML>", tmpl.compile());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue