modelattribute

Spring form ModelAttribute field validation to avoid 400 Bad Request Error

瘦欲@ 提交于 2019-12-21 04:46:12
问题 I've got an ArticleFormModel containing data sent by normal html form which is injected by Spring using @ModelAttribute annotation, i.e. @RequestMapping(value="edit", method=RequestMethod.POST) public ModelAndView acceptEdit(@ModelAttribute ArticleFormModel model, HttpServletRequest request, BindingResult errors) { //irrelevant stuff } Everything works perfectly fine up to some point. The problem is that the ArticleFormModel contains a double field ( protected , set using normal setter).

Dynamic form and data binding with Spring MVC

北慕城南 提交于 2019-12-20 12:27:51
问题 In my Spring MVC application I need to implement a dynamic questionnaire form: I have N questions and for each I have 3 options. So in my page I'll have something like this: | Question 1 | 1 | 2 | 3 | | Question 2 | 1 | 2 | 3 | | Question 3 | 1 | 2 | 3 | | ... | 1 | 2 | 3 | | Question N | 1 | 2 | 3 | Questions are stored in a database and for the options I'll use radio buttons. I'll use a forEach tag to creare dynamic rows, but I don't know how to post data and handle ModelAttribute binding

How to pass th:object values from html to controller

做~自己de王妃 提交于 2019-12-18 04:07:21
问题 How to pass thymeleaf(th:object) values to controller. HTML: <form id="searchPersonForm" action="#" th:object="${person}" method="post" > </form> SearchPersonController: @RequestMapping(value = "/modify/{pid}", method = RequestMethod.GET) public String modifyPersonData(Principal principal, @ModelAttribute("person") Person person, UserRoles userRoles, Model model, @PathVariable("pid") Long pid ) { //modify data } I am trying to pass like @ModelAttribute("person") Person person but this is not

@Autowired for @ModelAttribute

寵の児 提交于 2019-12-13 16:54:15
问题 I'm very new to Spring and I'm encountering the following problem. I've got the following Controller, in which the @Autowired works perfectly (tried debugging and it works fine). @Controller @RequestMapping(value = "/registration") @SessionAttributes("rf") public class RegistrationController { @Autowired UserJpaDao userDao; @RequestMapping(method = RequestMethod.GET) @Transactional public String setupForm(Model model) throws Exception { model.addAttribute("rf", new RegistrationForm()); return

KnockoutJS - Print iteration index as input name

邮差的信 提交于 2019-12-13 14:41:28
问题 I am trying to create my first KnockoutJS form view in combination with Spring MVC's @ModelAttribute binding. Data is loaded over Ajax and populated with KnockoutJS Data is added over KnockoutJS Data is removed over Ajax and KnockoutJS Data will be saved with an normal POST submit to Spring MVC controller. To bind the form inputs to a Spring MVC controller, I need the iteration index from KnockoutJS. So I tried following: But the values from my database are never bound like they are when I am

ModelAttribute not working with lists in spring

我的梦境 提交于 2019-12-11 20:43:03
问题 I want to bind a List using ModelAttribute. The list contains objects of type Transaction each of which contains transactionid (type int). This is my controller code: @RequestMapping(value = "/approvecreditdebit.do", method = RequestMethod.POST) public ModelAndView doActions(HttpServletRequest request, @ModelAttribute("clc") Clc transactionList, BindingResult result, ModelMap model) { /* * switch (action) { case "approve": */ System.out.println("Obj = " + transactionList.getClass()); System

ModelMap attribute not passing the value

ぐ巨炮叔叔 提交于 2019-12-11 10:23:51
问题 I am having issues with modelmap attributes.. this is my xyz.jsp file.. <select name="list"> <option value="-">Choose a Value</option> <c:forEach items="${sectionList}" var="section"> <option value="${section.code}">${section.description}</option> </c:forEach> </select> and the controller class... @RequestMapping(value="index", method = RequestMethod.GET) public String mainList(ModelMap modelMap){ modelMap.addAttribute("sectionList", sectionService.getAllSectionList()); return "home"; } But

Testing a spring controller method having @ModelAttribute as parameter

假如想象 提交于 2019-12-11 10:23:10
问题 I am trying to test a controller with this method: @RequestMapping(value="/test") public ModelAndView generateRecords(@ModelAttribute("Employee") Employee employee) { And I would like to know how can I create a unit testing for testing this. At the moment I am using: MockHttpServletRequest request = new MockHttpServletRequest(); request.setRequestURI("/test"); //request.setMethod("GET"); new AnnotationMethodHandlerAdapter().handle(request, new MockHttpServletResponse(), this.controller);

Hibernate Mapping two tables in one hbm file with same class name?

≡放荡痞女 提交于 2019-12-10 23:52:58
问题 I have 2 tables: CREATE TABLE "LOCATION" ( "ID" NUMBER(19,0) NOT NULL ENABLE, "VERSION" NUMBER(19,0) NOT NULL ENABLE, "DELETEULD" NUMBER(1,0) DEFAULT 0 NOT NULL ENABLE, "INBOUND" NUMBER(1,0) DEFAULT 0 NOT NULL ENABLE, "AAENABLED" NUMBER(1,0) DEFAULT 0 NOT NULL ENABLE, "WSUPLDTOOL" NUMBER(1,0) DEFAULT 0 NOT NULL ENABLE, "CISDEST" VARCHAR2(7 CHAR), "REVRECOVERY" NUMBER(1,0) DEFAULT 0, CONSTRAINT "LOCATION_ID" PRIMARY KEY ("ID") ENABLE ) CREATE TABLE "TSLD164"."FTP_SCAN_EVENTS" ( "HOSTNAME"

Spring MVC - difference between HttpSession.setAttribute and model.addObject

自闭症网瘾萝莉.ら 提交于 2019-12-09 06:35:48
问题 I am trying to learn Spring MVC recently. It seems that i did not understand well the functionalities of @ModelAttribute annotation and HttpSession. @SessionAttributes({"shoppingCart", "count"}) public class ItemController { @ModelAttribute("shoppingCart") public List<Item> createShoppingCart() { return new ArrayList<Item>(); } @ModelAttribute("count") public Integer createCount() { return 0; } @RequestMapping(value="/addToCart/{itemId}", method=RequestMethod.GET) public ModelAndView