rlynn
Jul 27th, 2005, 11:12 AM
I have a form and a SimpleFormController, and the values I enter are not getting to the controller.
The controller:
public DocumentFormController() {
setCommandName("doc");
setSessionForm(true);
}
/**
*
*/
public ModelAndView onSubmit(Object command, BindException errors)
throws ServletException
{
NewDocument doc = (NewDocument) command;
[b] //The following line has empty string for the title and not the title entered[/b]:
logger.info("doc TITLE is " + doc.getTitle() );
...
return new ModelAndView(new RedirectView(getSuccessView()));
} ...
The xml:
<!-- Validator and Form Controller for the "New Document" page -->
<bean id="createDocForm" class="com.myApp.web.DocumentFormController">
<property name="sessionForm"><value>true</value></property>
<property name="commandName"><value>doc</value></property>
<property name="commandClass"><value>com.myApp.business.NewDocument</value></property>
<property name="formView"><value>createdoc</value></property>
<property name="successView"><value>inbox.htm</value></property>
<property name="documentManager">
<ref bean="docMan"/>
</property>
<property name="userManager">
<ref bean="userMan"/>
</property>
</bean>
The jsp :
<%@ page session="false"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<%@ taglib prefix="spring" uri="/spring" %>
...
<form method="post" enctype="multipart/form-data" name="newdocument">
<table>
<tr>
<th>
Title
</th>
<td><spring:bind path="doc.title"><input type="text" name="title" size="40" maxlength="255" value="<c:out value="${status.value}"/>" /></spring:bind></td>
</tr>
<tr>
<th>
Purpose
</th>
<td><spring:bind path="doc.purpose"><textarea name="purpose" rows="6" cols="40"><c:out value="${status.value}"/></textarea></spring:bind></td>
</tr>
<tr>
<th>
</th>
<td><input type="submit" name="submit" value="Save" />
<input type="button" name="cancel" value="Cancel" onclick="history.back()" /></td>
</tr>
</table>
</form>
And the command class:
public class NewDocument
{
private String title;
private int statusId;
private int id;
private String purpose;
private int ownerId;
private User owner;
/**
*
* @param i
*/
public void setId(int i) {
id = i;
}
/**
*
* @return int
*/
public int getId() {
return id;
}
/**
*
* @param s
*/
public void setTitle(String s)
{
title = s;
}
/**
*
* @return String
*/
public String getTitle()
{
return title;
}
/**
*
* @param s
*/
public void setStatusId(int id)
{
statusId = id;
}
/**
*
* @return int
*/
public int getStatusId()
{
return statusId;
}
/**
*
* @param s
*/
public void setPurpose(String s)
{
purpose = s;
}
/**
*
* @return String
*/
public String getPurpose()
{
return purpose;
}
/**
*
* @param User
*/
public void setOwner(User u)
{
owner = u;
}
/**
*
* @return User
*/
public User getOwner()
{
return owner;
}
/**
* (delete??)
* @param s
*/
public void setOwnerId(int id)
{
ownerId = id;
}
/**
* (delete??)
* @return int
*/
public int getOwnerId()
{
return ownerId;
}
}
What is wrong with the above? I have implemented one other form and it works fine.
Thanks!
The controller:
public DocumentFormController() {
setCommandName("doc");
setSessionForm(true);
}
/**
*
*/
public ModelAndView onSubmit(Object command, BindException errors)
throws ServletException
{
NewDocument doc = (NewDocument) command;
[b] //The following line has empty string for the title and not the title entered[/b]:
logger.info("doc TITLE is " + doc.getTitle() );
...
return new ModelAndView(new RedirectView(getSuccessView()));
} ...
The xml:
<!-- Validator and Form Controller for the "New Document" page -->
<bean id="createDocForm" class="com.myApp.web.DocumentFormController">
<property name="sessionForm"><value>true</value></property>
<property name="commandName"><value>doc</value></property>
<property name="commandClass"><value>com.myApp.business.NewDocument</value></property>
<property name="formView"><value>createdoc</value></property>
<property name="successView"><value>inbox.htm</value></property>
<property name="documentManager">
<ref bean="docMan"/>
</property>
<property name="userManager">
<ref bean="userMan"/>
</property>
</bean>
The jsp :
<%@ page session="false"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<%@ taglib prefix="spring" uri="/spring" %>
...
<form method="post" enctype="multipart/form-data" name="newdocument">
<table>
<tr>
<th>
Title
</th>
<td><spring:bind path="doc.title"><input type="text" name="title" size="40" maxlength="255" value="<c:out value="${status.value}"/>" /></spring:bind></td>
</tr>
<tr>
<th>
Purpose
</th>
<td><spring:bind path="doc.purpose"><textarea name="purpose" rows="6" cols="40"><c:out value="${status.value}"/></textarea></spring:bind></td>
</tr>
<tr>
<th>
</th>
<td><input type="submit" name="submit" value="Save" />
<input type="button" name="cancel" value="Cancel" onclick="history.back()" /></td>
</tr>
</table>
</form>
And the command class:
public class NewDocument
{
private String title;
private int statusId;
private int id;
private String purpose;
private int ownerId;
private User owner;
/**
*
* @param i
*/
public void setId(int i) {
id = i;
}
/**
*
* @return int
*/
public int getId() {
return id;
}
/**
*
* @param s
*/
public void setTitle(String s)
{
title = s;
}
/**
*
* @return String
*/
public String getTitle()
{
return title;
}
/**
*
* @param s
*/
public void setStatusId(int id)
{
statusId = id;
}
/**
*
* @return int
*/
public int getStatusId()
{
return statusId;
}
/**
*
* @param s
*/
public void setPurpose(String s)
{
purpose = s;
}
/**
*
* @return String
*/
public String getPurpose()
{
return purpose;
}
/**
*
* @param User
*/
public void setOwner(User u)
{
owner = u;
}
/**
*
* @return User
*/
public User getOwner()
{
return owner;
}
/**
* (delete??)
* @param s
*/
public void setOwnerId(int id)
{
ownerId = id;
}
/**
* (delete??)
* @return int
*/
public int getOwnerId()
{
return ownerId;
}
}
What is wrong with the above? I have implemented one other form and it works fine.
Thanks!