java - How can I create an instance from a own class in FreeMarker (FTL) -


i wish instantiate java class have defined in domain , want use ftl code in way, i'm getting error.

<#assign myclassinstance = "com.domain.myclass"?new())> 

is possible? should change it?

myclass doesn't implements templatemodel

thanks!

there's no built-in function instantiating arbitrary non-templatemodel classes... maybe there should setting allow ?new. anyway, can write templatemethodmodelex that, , can pull of commonly included/imported templates <#assign unrestrictednew = "com.example.unrestrictednewmethodmodel"?new()> (or put instance data-model or configuration shared variable) , can <#assign myclassinstance = unrestrictednew("com.domain.myclass")(arg1, arg2, argn)> in templates. there 2 tricky parts in implementing such templatemethodmodel. 1 resolving class name class, recommend env.getnewbuiltinclassresolver().resolve(classname, env, null), env current freemarker.core.environment object. other calling constructor, have convert parameter values , possibly chose overloaded constructor. recommend calling ow = env.getobjectwrapper(), see if ow instanceof beanswrapper (throw exception if isn't), return ((beanswrapper) ow).newinstance(cl, arguments).


Comments

Popular posts from this blog

c# - Unity IoC Lifetime per HttpRequest for UserStore -

Change the color of an oval at click in Java AWT -

I am trying to solve the error message 'incompatible ranks 0 and 1 in assignment' in a fortran 95 program. -