robrant
robrant

Reputation: 317

Keycloak registration template loading error

I'm hitting an error when I attempt to register a new user in keycloak realm. I'm running keycloak in standalone mode on a Mac Yosemite. I'm new to keycloak, but have successfully created a new realm and configured it to work with a html/js example page served by a locally hosted apache web server. All in all pretty impressed; but would just like to figure out what I'm doing wrong with this register.ftl error.

Grateful for any pointers.

Here's the error:

22:25:43,034 ERROR [freemarker.runtime] (default task-115) Error executing FreeMarker template: freemarker.core.InvalidReferenceException: The following has evaluated to null or missing:
==> passwordRequired  [in template "register.ftl" at line 46, column 18]

Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing</#if>. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)??

FTL stack trace ("~" means nesting-related):
    - Failed at: #if passwordRequired  [in template "register.ftl" at line 46, column 13]
    ~ Reached through: #nested "form"  [in template "template.ftl" in macro "registrationLayout" at line 72, column 29]
    ~ Reached through: @layout.registrationLayout; section  [in template "register.ftl" at line 2, column 1]
----
at freemarker.core.InvalidReferenceException.getInstance(InvalidReferenceException.java:131)
at freemarker.core.UnexpectedTypeException.newDesciptionBuilder(UnexpectedTypeException.java:77)
    at freemarker.core.UnexpectedTypeException.<init>(UnexpectedTypeException.java:40)
    at freemarker.core.NonBooleanException.<init>(NonBooleanException.java:44)
    at freemarker.core.Expression.modelToBoolean(Expression.java:142)
    at freemarker.core.Expression.evalToBoolean(Expression.java:125)
    at freemarker.core.Expression.evalToBoolean(Expression.java:110)
    at freemarker.core.ConditionalBlock.accept(ConditionalBlock.java:46)
    at freemarker.core.Environment.visit(Environment.java:324)
    at freemarker.core.MixedContent.accept(MixedContent.java:54)
    at freemarker.core.Environment.visitByHiddingParent(Environment.java:345)
    at freemarker.core.IfBlock.accept(IfBlock.java:48)
    at freemarker.core.Environment.visit(Environment.java:324)
    at freemarker.core.Environment.invokeNestedContent(Environment.java:546)
    at freemarker.core.BodyInstruction.accept(BodyInstruction.java:56)
    at freemarker.core.Environment.visit(Environment.java:324)
    at freemarker.core.MixedContent.accept(MixedContent.java:54)
    at freemarker.core.Environment.visit(Environment.java:324)
    at freemarker.core.Macro$Context.runMacro(Macro.java:184)
    at freemarker.core.Environment.invoke(Environment.java:701)
    at freemarker.core.UnifiedCall.accept(UnifiedCall.java:84)
    at freemarker.core.Environment.visit(Environment.java:324)
    at freemarker.core.MixedContent.accept(MixedContent.java:54)
    at freemarker.core.Environment.visit(Environment.java:324)
    at freemarker.core.Environment.process(Environment.java:302)
    at freemarker.template.Template.process(Template.java:325)
    at <you get the idea...>

Upvotes: 2

Views: 4483

Answers (1)

BatteryAcid
BatteryAcid

Reputation: 8891

In my experience this is mostly due to a null attribute set in the form without a default/fallback value. You can make sure that attribute can't be set to null in your service or provide a default value:

myOptionalVar!myDefault

or:

<#if myOptionalVar??>
   when-present
<#else>
   when-missing
</#if>

Upvotes: 1

Related Questions