Potrzebuję przekazać wartość do kontrolera z poziomu HTML'a, jednak cały czas dostaję error:
freemarker.template.TemplateModelException: Method public org.springframework.web.servlet.support.BindStatus org.springframework.web.servlet.support.RequestContext.getBindStatus(java.lang.String) throws java.lang.IllegalStateException threw an exception when invoked on org.springframework.web.servlet.support.RequestContext@6bed32f3 with arguments of types [java.lang.String,]
Caused by: java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'workPosition' available as request attribute
Głównie chodzi o to, że użytkownik podaje jakąś wartość do input'a na stronie, ta wartość jest przekazywana do kontrolera i tam już na jej podstawie jest zwracany wynik. Jednak wysypuje się to po wejściu na stronę i wyświetlany jest powyższy błąd.
Kod kontrolera i html'a:
@Controller
public class AdminController
{
@Inject
private PersonEntityDao personDao;
private ModelAndView mav;
@RequestMapping( value = "/admin", method = RequestMethod.GET )
public String displayAdminPage()
{
return "admin";
}
@RequestMapping( value = "/findPerson", method = RequestMethod.POST )
public ModelAndView findByWorkPosition( @RequestParam( "workPosition" ) String workPosition )
{
this.mav = new ModelAndView( "people" );
if ( workPosition != null )
{
final List< PersonEntity > people = this.personDao.getAll().stream().filter( p -> p.getWorkPosition() == workPosition ).collect( Collectors.toList() );
this.mav.addObject( "peopleByWorkPosition", people );
}
return this.mav;
}
}
<html>
<body>
<form action="/add" method="post">
<@spring.formInput "workPosition" />
<input type="submit" value="Wyślij"/>
</form>
</body>
</html>
Moje pytanie to - jak to zrobić poprawnie? ;)
niezdecydowany