Keycloak注册模板加载错误

时间:2015-11-10 22:37:36

标签: templates freemarker keycloak

当我尝试在keycloak领域注册新用户时,我遇到了错误。我在Mac Yosemite上以独立模式运行keycloak。我是keycloak的新手,但已经成功创建了一个新领域,并将其配置为使用由本地托管的Apache Web服务器提供服务的html / js示例页面。总之令人印象深刻;但是我想知道我对这个register.ftl错误做错了什么。

感谢任何指针。

这是错误:

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...>

1 个答案:

答案 0 :(得分:1)

根据我的经验,这主要是由于在没有默认/回退值的表单中设置了null属性。您可以确保您的服务中的属性不能设置为null或提供默认值:

myOptionalVar!myDefault

或:

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