|
Java + Spring + Freemarker: FreeMarker template error. when-present<#else>when-missing
|
|||
---|---|---|---|
#18+
Всем привет! Есть сущность: Код: vbnet 1. 2. 3. 4. 5. 6.
Есть Freemarker шаблон с данными о пользователе, в частности возраст: Код: java 1.
При сохранении данных происходит валидация данных, с последующим возвратом в шаблон при наличии ошибки и перезаполнением правильных полей. По полю "age" получаю ошибку: авторfreemarker.core.InvalidReferenceException: The following has evaluated to null or missing: ==> user.age [in template "registration.ftl" at line 80, column 82] ---- Tip: It's the step after the last dot that caused this error, not those before it. ---- Tip: If the failing expression is known to 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: ${user.age} [in template "registration.ftl" at line 80, column 80] ---- Если меняю тип "age" в сущности "User" на "String" всё работает. ... |
|||
:
Нравится:
Не нравится:
|
|||
09.10.2018, 18:34 |
|
Java + Spring + Freemarker: FreeMarker template error. when-present<#else>when-missing
|
|||
---|---|---|---|
#18+
Molasar, А если попробовать заменить ${user.age} на ${user.age.value?html}, в порядке метода научного тыка. ... |
|||
:
Нравится:
Не нравится:
|
|||
09.10.2018, 18:39 |
|
Java + Spring + Freemarker: FreeMarker template error. when-present<#else>when-missing
|
|||
---|---|---|---|
#18+
Andy_OLAPMolasar, А если попробовать заменить ${user.age} на ${user.age.value?html}, в порядке метода научного тыка. FTL stack trace ("~" means nesting-related): - Failed at: ${user.age.value?html} [in template "registration.ftl" at line 80, column 80] ----] with root cause freemarker.core.InvalidReferenceException: The following has evaluated to null or missing: ==> user.age [in template "registration.ftl" at line 80, column 82] ... |
|||
:
Нравится:
Не нравится:
|
|||
09.10.2018, 18:47 |
|
Java + Spring + Freemarker: FreeMarker template error. when-present<#else>when-missing
|
|||
---|---|---|---|
#18+
Для null or missing другой синтаксис: ${user.age.value!"null or missing"} https://freemarker.apache.org/docs/dgui_template_exp.html#dgui_template_exp_missing_default ... |
|||
:
Нравится:
Не нравится:
|
|||
09.10.2018, 19:41 |
|
Java + Spring + Freemarker: FreeMarker template error. when-present<#else>when-missing
|
|||
---|---|---|---|
#18+
Alexander A. SakДля null or missing другой синтаксис: ${user.age.value!"null or missing"} https://freemarker.apache.org/docs/dgui_template_exp.html#dgui_template_exp_missing_default авторfreemarker.core.InvalidReferenceException: The following has evaluated to null or missing: ==> user.age [in template "registration.ftl" at line 80, column 82] ---- Tip: It's the step after the last dot that caused this error, not those before it. ---- Tip: If the failing expression is known to 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: ${user.age.value!"null or missing"} [in template "registration.ftl" at line 80, column 80] ---- ... |
|||
:
Нравится:
Не нравится:
|
|||
09.10.2018, 21:15 |
|
Java + Spring + Freemarker: FreeMarker template error. when-present<#else>when-missing
|
|||
---|---|---|---|
#18+
Ну да. Копипаст - зло. "value" там лишнее конечно же. Нет такого свойства у Integer. ${user.age!"null or missing"} ... |
|||
:
Нравится:
Не нравится:
|
|||
09.10.2018, 22:03 |
|
Java + Spring + Freemarker: FreeMarker template error. when-present<#else>when-missing
|
|||
---|---|---|---|
#18+
Alexander A. SakНу да. Копипаст - зло. "value" там лишнее конечно же. Нет такого свойства у Integer. ${user.age!"null or missing"} Спасибо! Разобрался. ... |
|||
:
Нравится:
Не нравится:
|
|||
10.10.2018, 13:14 |
|
|
start [/forum/topic.php?fid=59&fpage=38&tid=2121723]: |
0ms |
get settings: |
8ms |
get forum list: |
15ms |
check forum access: |
3ms |
check topic access: |
3ms |
track hit: |
35ms |
get topic data: |
11ms |
get forum data: |
6ms |
get page messages: |
42ms |
get tp. blocked users: |
2ms |
others: | 13ms |
total: | 138ms |
0 / 0 |