Cannot access method of POJO
Stefan Großhauser <[email protected]> Wed, 26 Jan 2022 09:54:38 +0100
| Newsgroups | gmane.comp.jakarta.velocity.user |
|---|---|
| Message-ID | <[email protected]> |
--=-ONdCKdG3npvrDqQKyKNW Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Hello everyone=2C I am trying to introduce a simple POJO as my own Tool=2E I have tried to reduce it to a minimal Example which I will list below=2E= I can see that the POJO ist available in the template=2C=20 but I am not able to access its function=2C whatever I try=2E There must be= something I am doing wrong here=2E We include Version 2=2E3 in our build=2Egradle=2E implementation =28=27org=2Eapache=2Evelocity=3Avelocity-engine-core=3A2=2E3= =27=29=20 Maybe somebody here is able to give me a hint=3F I would be very grateful about any advice because I only find examples whic= h make me think that my code should be alright=2E=2E=2E cheers Stefan ///////////////// MyClass=2Ejava Begin package mypackage=3B public class MyClass =7B =C2=A0=C2=A0=C2=A0 class Toolbox =7B =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 String rot13=28String s=29 =7B= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 StringBu= ffer ret =3D new StringBuffer=28=29=3B =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 for =28i= nt i =3D 0=3B i =3C s=2Elength=28=29=3B i++=29 =7B =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 char c =3D s=2EcharAt=28i=29=3B =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 if=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =28c =3E=3D =27a= =27 =26=26 c =3C=3D =27m=27=29 c +=3D 13=3B =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 else if=C2=A0 =28c =3E=3D =27A=27 =26=26 c =3C=3D =27M= =27=29 c +=3D 13=3B =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 else if=C2=A0 =28c =3E=3D =27n=27 =26=26 c =3C=3D =27z= =27=29 c -=3D 13=3B =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 else if=C2=A0 =28c =3E=3D =27N=27 =26=26 c =3C=3D =27Z= =27=29 c -=3D 13=3B =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 ret=2Eappend=28c=29=3B =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =7D =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return r= et=2EtoString=28=29=3B =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =7D =C2=A0=C2=A0=C2=A0 =7D =C2=A0=C2=A0=C2=A0 public String render=28=29 throws Exception =7B =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 VelocityContext context =3D new= VelocityContext=28=29=3B =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 // put a POJO to make some usefu= l functions accessible in templates =C2=A0=C2=A0 context=2Eput=28=22TEMPLATE=5FNAME=22=2C =22mytemplate=22= =29=3B =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 context=2Eput=28=22toolbox=22=2C= new Toolbox=28=29=29=3B =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=20 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 VelocityEngine ve =3D new Veloci= tyEngine=28=29=3B =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 // define the logger name that i= s used in log messages by Velocity =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ve=2EsetProperty=28VelocityEngin= e=2ERUNTIME=5FLOG=5FNAME=2C =22VelocityEngine=22=29=3B =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 // activate the Classpath resour= ce loader =28see also https=3A//velocity=2Eapache=2Eorg/engine/devel/apidoc= s/index=2Ehtml=29 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ve=2EsetProperty=28=22resource= =2Eloaders=22=2C =22class=22=29=3B =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ve=2EsetProperty=28=22resource= =2Eloader=2Eclass=2Eclass=22=2C =22org=2Eapache=2Evelocity=2Eruntime=2Ereso= urce=2Eloader=2EClasspathResourceLoader=22=29=3B =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ve=2EsetProperty=28=22runtime=2E= strict=5Fmode=2Eenable=22=2C =22true=22=29=3B =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 // after setting properties we m= ay now initialize the engine =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ve=2Einit=28=29=3B =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=20 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Template= template =3D ve=2EgetTemplate=28=22mytemplate=2Evm=22=2C =22UTF-8=22=29=3B= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 StringWr= iter sw =3D new StringWriter=28=29=3B =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 template= =2Emerge=28 context=2C sw =29=3B =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return s= w=2EtoString=28=29=29=3B =C2=A0=C2=A0=C2=A0 =7D =7D ///////////////// MyClass=2Ejava End This is my template=3A =23=23=23=23=23=23=23=23=23 mytemplate=2Evm Begin =7BPC001=3B0030=2C0015=2C1=2C1=2CO=2C11=2CB=3D=24toolbox=2Erot13=28=22test= =22=29 =24toolbox=2ERot13=28=24TEMPLATE=5FNAME=29 =24TEMPLATE=5FNAME =24too= lbox=C2=A0 =7C=7D =23=23=23=23=23=23=23=23=23 mytemplate=2Evm End With the strict mode=2C I learn that Velocity does not see the rot13=28=29= method=3A ------------------ Output Start org=2Eapache=2Evelocity=2Eexception=2EMethodInvocationException=3A Object= =27mypackage=2EMyClass=24Toolbox=27 does not contain method rot13=28java= =2Elang=2EString=29 at velocity/header=2Evm=5Bline 8=2C column 38=5D ------------------- Output End Without the strict mode=2C I see the output=3A =7BPC001=3B0030=2C0015=2C1=2C1=2CO=2C11=2CB=3D=24toolbox=2Erot13=28=22test= =22=29 =24toolbox=2ERot13=28=24TEMPLATE=5FNAME=29 artikel mypackage=2EMyCla= ss=24Toolbox=406b419da=C2=A0 =7C=7D =20 JETZT NEWSLETTER ABONNIEREN=3A https=3A//hammerbacher=2Ecom/newsletter-anme= ldung/ Hammerbacher GmbH Gesch=C3=A4ftsf=C3=BChrer Bernhard Hammerbacher=2C Ursula= Hammerbacher Registergericht N=C3=BCrnberg HRB 10908 =20 =09Hausanschrift Daimlerstra=C3=9Fe 4-6 D 92318 Neumarkt =09Telefon +49=280=299181 2592-0 =09Telefax +49=280=299181 2592-28 =09E-Mail info=40hammerbachergmbh=2Ede www=2Ehammerbacher=2Ecom =20 Haftungsausschluss / Disclaimer=20 Die Informationen=2C die in dieser Kommunikation enthalten sind=2C sind aus= schlie=C3=9Flich und allein f=C3=BCr den Empf=C3=A4nger bestimmt=2E Die Ver= wendung durch Dritte ist untersagt=2E Die Firma Hammerbacher GmbH ist nur f= =C3=BCr die von ihr eingegeben Informationen verantwortlich=2C jedoch nicht= f=C3=BCr die einwandfreie =C3=9Cbertragung oder im Zusammenhang mit der=20= =C3=9Cbertragung oder dem Empfang eingetretene Ver=C3=A4nderungen oder Verz= =C3=B6gerungen=2E Diese E-Mail enth=C3=A4lt vetrtrauliche und/oder rechtlich gesch=C3=BCtzte= Informationen=2E Wenn Sie nicht der richtige Adressat sind oder diese E-Ma= il irrt=C3=BCmlich erhalten=C2=A0 haben=2C informieren Sie bitte sofort den= Absender und vernichten Sie diese E-Mail=2E Das unerlaubte Kopieren sowie= die unbefugte Weitergabe dieser Mail ist nicht gestattet=2E --=-ONdCKdG3npvrDqQKyKNW--