How to pass values from Java to the FTL-based pages?

525 views
Skip to first unread message

DP

unread,
Dec 23, 2022, 9:52:55 AM12/23/22
to Keycloak User
Hello!

Imagine I want to display some values generated in my Java classes to the pages based on Freemarker (FTL) templates.

That is, let's say I have the following code:

final Response response = smsCodeForm
        .setAttribute("myText", "12")
        .createForm("some-form.ftl");
context.challenge(response);


I want the value of myText ("12") to appear in the form rendered based on the some-form.ftl file.

I tried putting

<p>${msg('myText')}</p>

but it produces an empty text.

<p>${myText}</p> results in an error (property not defined).

What do I need to do

a) in my Java code and
b) the FTL template

in order to display values generated in Java in that form?

Thanks in advance

Dmitrii Pisarenko

Łukasz Dywicki

unread,
Jan 3, 2023, 12:51:55 PM1/3/23
to keyclo...@googlegroups.com
Hello Dmitrii,
The ${msg('myText')} macro is used for i18n lookups, hence it will not
work unless you provision proper translation resources.
Other part of your code, assuming that smsCodeForm is created by
authenticationFlowContext.form() call looks good. I've used this
approach with Keycloak 15, it should work up to 18. Quarkus distribution
which is, as far I know, default since 18th release should not amend that.

Best regards,
Łukasz Dywicki
--
Code-House
http://code-house.org
> --
> You received this message because you are subscribed to the Google
> Groups "Keycloak User" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to keycloak-use...@googlegroups.com
> <mailto:keycloak-use...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/keycloak-user/3d6a6d63-bbfc-4fe4-9600-dcbe2e10ba67n%40googlegroups.com <https://groups.google.com/d/msgid/keycloak-user/3d6a6d63-bbfc-4fe4-9600-dcbe2e10ba67n%40googlegroups.com?utm_medium=email&utm_source=footer>.
Reply all
Reply to author
Forward
0 new messages