Here's the code
Code:
package com.example.web;
import java.util.ArrayList;
import java.util.List;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;
import com.example.dao.DogDao;
import com.example.dao.PersonDao;
import com.example.model.Dog;
import com.example.model.Person;
public class PersonDogsFormController extends SimpleFormController
{
public PersonDogsFormController() {
this.setCommandClass(Person.class);
this.setCommandName("person");
}
private DogDao dogDao;
private PersonDao personDao;
String str2;
protected final Log logger = LogFactory.getLog(getClass());
public Object formBackingObject(HttpServletRequest request) throws Exception
{
System.out.println("This logging appears each time update is pressed ");
Person p = (Person) personDao.find(Person.class, Long.parseLong(request.getParameter("id")));
List dogList = new ArrayList();
dogList = dogDao.findQuery("from Dog as d where d.person_id = "+ p.getId() + " order by d.name ");
request.setAttribute("theDogs", dogList);
return p;
}
protected void onFormChange(ActionRequest request, ActionResponse response, Object command) {
}
// ModelAndView onSubmit(Object command, BindException bindException)
//{
//Person givenData = (Person) command;
/* The givenData object now contains the successfully validated data from the
* form, so can be written to a database, or whatever.
*/
/*
personDao.savePerson(givenData);
Person p = (Person) personDao.find(Person.class, givenData.getId());
return new ModelAndView(getSuccessView(), "model", p);
*/
// }
public DogDao getDogDao() {
return dogDao;
}
public void setDogDao(DogDao DogDao) {
this.dogDao = DogDao;
}
public PersonDao getPersonDao() {
return personDao;
}
public void setPersonDao(PersonDao personDao) {
this.personDao = personDao;
}
}
Code:
<%@ page import="java.util.*,com.example.model.*" %>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
<html>
<head>
<style type="text/css">
div#test {position:absolute; right:0; top:0; repeat:y; background:#193b8b; width:180px; height:1000px}
div#test2 {position:absolute; left:0; top:0; repeat:y; background:#193b8b; width:180px; height:1000px}
div#container {position:absolute; padding-left:50px; left:180; right:180; top:0; repeat:y; background:gray; height:1000px}
div#header {text-align:center}
</style>
</head>
<body>
<div id="test">
</div>
<div id="container">
<div id="header">
<h1>Test Page</h1>
</div>
<h1 align="center">Person's Dogs</h1>
<br>
<form:form method="post" action="persondogs.htm" commandName="person">
Name </br><form:input path="name" />
<form:hidden path="id"/>
</br>
<p>
Dogs
</br>
<c:if test="${!empty person.dogs}">
</c:if>
</br>
<c:forEach items="${theDogs}" var="i" varStatus="itemsRow">
<form:input path="dogs[${i.id}].name"/><form:input path="dogs[${i.id}].type"/><form:input path="dogs[${i.id}].id"/></br>
</c:forEach>
</br>
<input type="submit" value="Update" />
</form:form>
</div>
<div id="test2">
</div>
<
</body>
</html>
Code:
May 26, 2010 5:48:32 PM org.apache.catalina.startup.HostConfig checkResources
INFO: Reloading context [/HelloWorld]
log4j:WARN No appenders could be found for logger (org.springframework.web.context.ContextLoader).
log4j:WARN Please initialize the log4j system properly.
This logging appears each time update is pressed
DEBUG in dao
This logging appears each time update is pressed
DEBUG in dao
This logging appears each time update is pressed
DEBUG in dao
This logging appears each time update is pressed
DEBUG in dao
This logging appears each time update is pressed
DEBUG in dao
This logging appears each time update is pressed
DEBUG in dao
This logging appears each time update is pressed
DEBUG in dao
This logging appears each time update is pressed
DEBUG in dao
This logging appears each time update is pressed
DEBUG in dao
This logging appears each time update is pressed
DEBUG in dao