On 16. 10. 22 17:21,
jems....@gmail.com wrote:
> Hi,
>
> I have this case where i have this extension called "field"
>
> /public class FieldTemplateExtension {
> static final String FIELD = "field";
>
> /**
> * Can be called like this {field_name:email}.
> *
> * @see FieldName
> * @param propertyName the field enum name
> * @return the field name
> */
> @TemplateExtension(namespace = FIELD, matchName = ANY)
> static Object getConfigProperty(String propertyName) {
> return FieldName.valueOf(propertyName.toUpperCase()).toString();
> }
> }/
>
> The idea behind this is that i keep an enum of field names that i use to
> name form fields instead of using hard coded values that can be hard to
> change after.
>
> So on the backend side i use this enum for instance to retrieve a
> parameter value that has been posted by the user and on the front side
> in Qute i use them in my html templates to give a name to an input field
> for instance
>
> <input type="email" name="{field.email}" />
>
> This works correctly but i want to be able to do also is to be able to
> also inject some parameters and be able to keep the same logic to test
> for their value/existance without using a hard coded parameter name in
> Qute template
I'm not quite sure I fully understand your question but you might define
you template extension method like this:
@TemplateExtension(namespace = FIELD)
static Object get(String propertyName) {
return FieldName.valueOf(propertyName.toUpperCase()).toString();
}
And then in the template use: {field:get(nameOfTheField)}.
Note that "get" is derived from the method name by default. And the
"nameOfTheField" is evaluated first and then passed to the template
extension method as the "propertyName" argument.
>
> I tried this
>
> {#let activated=field:activated}
> ...
> {/let}
>
> But the issue when doing this is that field:activated will be translated
> to the parameter name and that's it where in my case i want to also
> retrieve its value if its defined using this enum. Is this possible ? is
> there another approach, a cleaner one maybe ?
>
> Thank you
>
> Regards,
>
> --
> You received this message because you are subscribed to the Google
> Groups "Quarkus Development mailing list" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to
quarkus-dev...@googlegroups.com
> <mailto:
quarkus-dev...@googlegroups.com>.
> To view this discussion on the web visit
>
https://groups.google.com/d/msgid/quarkus-dev/c04e8d92-3d16-416f-b592-5c6b3eeea48en%40googlegroups.com <
https://groups.google.com/d/msgid/quarkus-dev/c04e8d92-3d16-416f-b592-5c6b3eeea48en%40googlegroups.com?utm_medium=email&utm_source=footer>.
--
Martin Kouba
Software Engineer
Red Hat, Czech Republic