Dropdown box - from Spring MVC model / context to form using freemarker

前端 未结 2 1474
广开言路
广开言路 2021-01-13 03:21

This should be very basic but I can\'t find anything about it in the web, just bits and pieces that I don\'t seem able to fit together..

We\'re using Spring MVC with

2条回答
  •  情歌与酒
    2021-01-13 04:19

    After much rephrasing and rethinking I finally discovered the solution:

    First

    I need to have a bean hold my choice obviously

    Second

    The options need to be initialized as a String list and provided by Spring MVC to the page:

    public ModelAndView get() {
    
        // ...
        ModelAndView mav = new ModelAndView();
        List options = Arrays.asList(getOptionsFromDatabaseAndConvertToStringList());
        mav.addObject("options",options );
        mav.setViewName("someview");
    
        return mav;
    }
    

    Third

    options now need to be bound in the freemarker template and can then be accessed like any other freemarker variable (i.e. NO quotation marks):

    <@spring.bind "options" />
    
    
    <@spring.formSingleSelect "targetBean.choice", options, " " />

提交回复
热议问题