Monday, April 9, 2018, 8:34:27 PM, Woonsan Ko wrote:

> Hi,
>
> While trying to implement directives to replace Spring MVC select,
> options and option tags [1], I'm wondering what is the best to nest
> options or option directive inside form directive.

Or, you mean the "select" directive?

> One straightforward option is:
>
> <@form.select 'user.favoriteSport'; form>
>   <@option form value="NONE" label="--- Select ---" />
>   <@options form items=sports />
> </@form>
>
> As we don't have something like
> javax.servlet.jsp.tagext.TagSupport#findAncestorWithClass(Tag, Class)

Yeah, and we should have that. This is something that's missing from
FM2 for a long time too... it's in my "most frequently missed
features" FM2 TODO list. Maybe in 2.3.29.

> (bottom to top), we can pass the form directive model to the nested
> content like org.apache.freemarker.spring.model.BindDirective does
> already (top to bottom).

No way, that's way too awkward for the user (especially if you
consider factoring out <@option ... />-s into macros). For now you
should just use Environment.getCustomState(CustomStateKey) to maintain
some state object where you keep track of the current context. (The
main problem with that feature is that there's no template language
feature to access it. Like you can't write two macros that exchange
information through that, purely in the template language. But in your
case that's not a problem, as you implement everything in Java.)

> So, developers are needed to pass it along like the above example,
> unless it is as simple as one-liner like the following:
>
> <@form.select 'user.favoriteSport' items=sports />
>
> Does it sounds good? Or do you have any better ideas?
>
> Regards,
>
> Woonsan
>
> [1] https://www.mkyong.com/spring-mvc/spring-mvc-dropdown-box-example/
>

-- 
Thanks,
 Daniel Dekany

Reply via email to