2017-10-06 3 views
0

Ich versuche, einfache Listenwerte mit Federcontroller in die Auswahlbox zu drucken. Es liefert erfolgreich alle Werte unter VerwendungFeder <form:select> druckt nichts

, aber während ich das versuche, funktioniert es nicht. Die Lösung wird es zu schätzen wissen.

Controller

@RequestMapping(value="/flight", method = RequestMethod.GET) 
public ModelAndView homePage(CountryCodes country) { 
    //model.addAttribute("userName", user.getUserName()); 
    /*List<CountryCodes> countryCodes = userService.getCountryCodes(); 
    model.addAttribute("codes", countryCodes);*/ 

    ModelAndView mv= new ModelAndView("FlightDetails"); 
    List<String> test = new ArrayList<String>(); 
    test.add("Human Resources"); 
    test.add("Finance"); 
    test.add("Admin"); 
    test.add("Quality Assurance"); 
    test.add("Products"); 

    mv.addObject("test", test); 
    return mv; 
} 

Auswahlbox in jsp

${test} 
<form:select path="country" class="form-control"> 
    <form:options items="${test}" class="form-control"/> 
</form:select> 

Antwort

0

Haben schließen Sie die spring:form taglib Referenz? Auf diese Weise funktioniert für mich:

Controller:

@RequestMapping(value="/flight", method = RequestMethod.GET) 
    public ModelAndView homePage(CountryCodes country) { 
     //model.addAttribute("userName", user.getUserName()); 
     /*List<CountryCodes> countryCodes = userService.getCountryCodes(); 
     model.addAttribute("codes", countryCodes);*/ 

     ModelAndView mv= new ModelAndView("FlightDetails"); 
     List<String> test = new ArrayList<String>(); 
     test.add("Human Resources"); 
     test.add("Finance"); 
     test.add("Admin"); 
     test.add("Quality Assurance"); 
     test.add("Products"); 

     mv.addObject("test", test); 
     mv.addObject("country", country); 
     return mv; 
    } 

JSP:

<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%> 
<html> 
     <head> 
      <title>Select options from controller</title> 
     </head> 
     <body> 
      <h1>Select options from controller</h1> 
      ${test} 
      <form:select path="country" class="form-control"> 
       <form:options items="${test}" class="form-control"/> 
      </form:select> 
     </body> 

    </html>