Hi. I just started using handlebars java yesterday. I could not get something simple like this to render:
varhandlebars = newHandlebars.registerHelperMissing((context, options) -> {
thrownewRuntimeException(
String.format("Unregistered helper name %s rendering %s.", options.helperName, options.fn.text()));
});
varmyObj = newMyObject();
varmyObj .setFirstName("Luke");
myObj .getRelationship().setName("father");
vartemplate = handlebars.compileInline("{{ firstName }}, I am your {{ relationship.name }}.");
varres = template.apply(myObj);Every time, it threw saying it couldn't find firstName. I tried using fluent named accessors, exposing the fields directly, etc but no change in the names or access would get it to work. I could get it working by passing in a map, but not a POJO.
After a lot of searching documentation where others said it should "just work" out of the box, I stumbled on a code sample of someone who was explicitly setting the resolvers of the context:
varcontext = Context.newBuilder(myObj)
.resolvers(JavaBeanValueResolver.INSTANCE, FieldValueResolver.INSTANCE)
.build();
varres = template.apply(context);
This works like a charm.
But why doesn't it work "out of the box?" Or can we update the docs to reflect that you need to specify the resolvers for java objects?
I'm using version 4.1.2.
Hi. I just started using handlebars java yesterday. I could not get something simple like this to render:
Every time, it threw saying it couldn't find
firstName. I tried using fluent named accessors, exposing the fields directly, etc but no change in the names or access would get it to work. I could get it working by passing in a map, but not a POJO.After a lot of searching documentation where others said it should "just work" out of the box, I stumbled on a code sample of someone who was explicitly setting the resolvers of the context:
This works like a charm.
But why doesn't it work "out of the box?" Or can we update the docs to reflect that you need to specify the resolvers for java objects?
I'm using version 4.1.2.