ela1109
Jun 21st, 2012, 04:51 AM
Hello,
In my database I have table Person. In my entity class Person.class beside all other data (name, age,...) I have Boolean forGrouping field. In my application I have all dao, jdbc_dao, service and controller classes and packages and all works perfect. I use jsp for view data and ModelAndView in controller. My 'procedureForAllPersons' returns List<Person> but when I put List<Person> in '@ModelAttribute(value="allPersons") Person allPersons' in doGrouping I got error.
PersonController.java
package net.jdj.coffee.web;
...
@Controller
@SessionAttributes({"userSession"})
@RequestMapping("/person.htm")
public class PersonController {
...
@RequestMapping(method=RequestMethod.GET)
public String showForm(ModelMap model, @ModelAttribute UserSession userSession) {
...
model.addAttribute("allPersons", procedureForAllPersons);
...
return "person";
}
@RequestMapping(params="group=true", method=RequestMethod.POST)
public String doGrouping(
@ModelAttribute(value="allPersons") Person allPersons,
BindingResult result, @ModelAttribute UserSession userSession) {
String putanja = "wrongGrouping.htm";
// now i want to do something only with records with forGrouping checked
... THIS IS WHAT I DON T NOW!
if (ok) {
putanja = "goodGrouping.htm" }
return "redirect:" + putanja;
}
}
Person.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page session="false"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<html>
<head>...</head>
<body>
<!-- Main Page Container -->
<div class="page-container">
...
<!-- B.1 MAIN CONTENT -->
<div class="main-content">
<!-- Content unit - One column -->
<div class="column1-unit">
<form:form commandName="allPersons"
action="person.htm?group=true" name="formGrouping">
<fieldset>
<c:if test="${!empty allPersons}">
<table width="90%">
<thead>
<tr>
<th width="15px" style="display: none"></th>
<th width="15px">?</th>
<th width="40px">name</th>
...
</tr>
</thead>
<tbody>
<c:forEach items="${allPersons}" var="persons">
<tr id="${persons.id}" >
<td><form:input type="checkbox" name="forGrouping" id="forGrouping" path="forGrouping" value="${persons.forGrouping}"/></td>
<td><c:out value="${persons.name}"/></td>
...
</tr>
</c:forEach>
</tbody>
</table>
</c:if>
<p><input type="submit" value="Do grouping" /></p>
</fieldset>
</form:form>
</div>
<hr class="clear-contentunit" />
</div>
</div>
<!-- C. FOOTER AREA -->
...
</div>
</body>
</html>
User in list of persons some persons ckeck and click submit.
My question is: How to read allPersons after submit? It is List<Person> with new value of some forGrouping (in only some records) but I don t know how to read which records are checked and which are not.
I am looking for examples in net for last two weeks but my English is not good enough to ask good question in Google.
Thanks, Ela
In my database I have table Person. In my entity class Person.class beside all other data (name, age,...) I have Boolean forGrouping field. In my application I have all dao, jdbc_dao, service and controller classes and packages and all works perfect. I use jsp for view data and ModelAndView in controller. My 'procedureForAllPersons' returns List<Person> but when I put List<Person> in '@ModelAttribute(value="allPersons") Person allPersons' in doGrouping I got error.
PersonController.java
package net.jdj.coffee.web;
...
@Controller
@SessionAttributes({"userSession"})
@RequestMapping("/person.htm")
public class PersonController {
...
@RequestMapping(method=RequestMethod.GET)
public String showForm(ModelMap model, @ModelAttribute UserSession userSession) {
...
model.addAttribute("allPersons", procedureForAllPersons);
...
return "person";
}
@RequestMapping(params="group=true", method=RequestMethod.POST)
public String doGrouping(
@ModelAttribute(value="allPersons") Person allPersons,
BindingResult result, @ModelAttribute UserSession userSession) {
String putanja = "wrongGrouping.htm";
// now i want to do something only with records with forGrouping checked
... THIS IS WHAT I DON T NOW!
if (ok) {
putanja = "goodGrouping.htm" }
return "redirect:" + putanja;
}
}
Person.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page session="false"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<html>
<head>...</head>
<body>
<!-- Main Page Container -->
<div class="page-container">
...
<!-- B.1 MAIN CONTENT -->
<div class="main-content">
<!-- Content unit - One column -->
<div class="column1-unit">
<form:form commandName="allPersons"
action="person.htm?group=true" name="formGrouping">
<fieldset>
<c:if test="${!empty allPersons}">
<table width="90%">
<thead>
<tr>
<th width="15px" style="display: none"></th>
<th width="15px">?</th>
<th width="40px">name</th>
...
</tr>
</thead>
<tbody>
<c:forEach items="${allPersons}" var="persons">
<tr id="${persons.id}" >
<td><form:input type="checkbox" name="forGrouping" id="forGrouping" path="forGrouping" value="${persons.forGrouping}"/></td>
<td><c:out value="${persons.name}"/></td>
...
</tr>
</c:forEach>
</tbody>
</table>
</c:if>
<p><input type="submit" value="Do grouping" /></p>
</fieldset>
</form:form>
</div>
<hr class="clear-contentunit" />
</div>
</div>
<!-- C. FOOTER AREA -->
...
</div>
</body>
</html>
User in list of persons some persons ckeck and click submit.
My question is: How to read allPersons after submit? It is List<Person> with new value of some forGrouping (in only some records) but I don t know how to read which records are checked and which are not.
I am looking for examples in net for last two weeks but my English is not good enough to ask good question in Google.
Thanks, Ela