You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Update docs to specify need for explicit resolvers #992
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:
I'm hoping someday @jknack will take my PR #962 because I expect more and more folks to be even more confused with Value Resolver behavior changing on Java upgrade.
That is why in general right now I recommend you should set the Value Resolvers.
Activity
agentgt commentedon Sep 7, 2022
The default resolvers for using the builder can be seen here:
handlebars.java/handlebars/src/main/java/com/github/jknack/handlebars/Context.java
Line 261 in 52edac9
And its defined here:
handlebars.java/handlebars/src/main/java/com/github/jknack/handlebars/ValueResolver.java
Line 37 in 52edac9
What version of Java are you using (it should not matter since you are using 4.1.2 but I'm curious anyway)?
Anyway my guess is
MyObjectis either notpublicand or its getters are notpublic.I highly recommend you do not use the
FieldValueResolverif you plan on upgrading (unless of course you want to make your fieldspublic).One gotcha in
4.3.0is if you upgrade Java you will get different behavior because:I'm hoping someday @jknack will take my PR #962 because I expect more and more folks to be even more confused with Value Resolver behavior changing on Java upgrade.
That is why in general right now I recommend you should set the Value Resolvers.