PDA

View Full Version : data omission in ModelAndView onSubmit


HaasHenry
Jun 14th, 2007, 02:34 PM
I'm using Spring 2.0.5 with the SimpleFormController. I'm using my formBackingObject to pre-populate my JSP along with referenceData to populate my combo box on the JSP. The formBackingObject uses a PagedListHolder to fill my dataTable, which incidentally are all non-input fields. The referenceData in my combo box is the only data that will be changed.

When I get to my ModelAndView onSubmit, the only parmater values I see are from the combo box. I need to be able to see the id from each row too. The id is a hidden input field in the dataTable.

Any suggestions are appreciated. I'm VERY new at this.
Thank you

Steve O
Jun 14th, 2007, 02:42 PM
Would you post your relevant code? (code tags are great!)

That would make it so much easier to help you out.

Steve O

HaasHenry
Jun 14th, 2007, 03:14 PM
Thank you for your quick reply. Please let me know what else I can supply to help with this issue. Any direction is appreciated....

Here is part of the controller:


public class MajMinorappController extends SimpleFormController {
private MajMinorFacade majorMinor;
String traceMsg ="";
String traceClass = "MajMinorappController";
String traceMethod ="";

private String cadPid= null;
private String cadName = null;

private Utilities utilities;

public MajMinorappController() {
setSessionForm(true);
setCommandName("cadetList");
setFormView("AssignMajMinor");

}


protected Object formBackingObject(HttpServletRequest request) throws Exception {
logger.debug("formbackingobject");
/* this is the PagedListHolder example */
Map model = new HashMap();
PagedListHolder cadetList =
new PagedListHolder(this.majorMinor.getCadetsNoMajor() );
cadetList.setPageSize(1500);

request.getSession().setAttribute("ViewCadetsNoMajor_cadetList", cadetList);
model.put("cadetList", cadetList);
logger.debug("end of formbackingobject");

logger.debug("***VALUES *** " + request.getAttribute("cadetList.pid"));

return cadetList;

}

/* Logger for this class and subclasses */
protected final Log logger = LogFactory.getLog(getClass());

public void setMajorMinor(MajMinorFacade majorMinor){
traceMethod = "setMajorMinor";
this.majorMinor = majorMinor;
}

/* reference data for the combo list for staff majors */
protected Map referenceData(HttpServletRequest request) {
try{
List lst = this.majorMinor.getStaffMajors();
Map model = new HashMap();
model.put("lst", lst);
logger.debug("***end of map reference***");

return model;

}
catch(NullPointerException e){
traceMethod="refdata";
System.out.println("NULL POINTER EXCEPTION AGAIN!!!!");

Map model = new HashMap();
PagedListHolder majorList = new PagedListHolder(this.majorMinor.getStaffMajors());
majorList.setPageSize(50);
request.getSession().setAttribute("ViewStaffMajors_majorList", majorList);
model.put("majorList", majorList);
return model;
}
}

protected ModelAndView onSubmit (HttpServletRequest request,
HttpServletResponse response,
Object command,
BindException errors) throws Exception {
super.showForm(request, response, errors);

logger.debug("***ONSUBMIT IN CONTROLLER***");
logger.debug("cadName is: " + request.getParameter("nameFull"));

java.util.Enumeration ee = request.getParameterNames();
while (ee.hasMoreElements()) {
String key = (String)ee.nextElement();
String[] values = request.getParameterValues(key);
logger.debug("**Enumerating over request " + key + " = ");
for(int i = 0; i < values.length; i++) {
logger.debug(values[i] + " ");
}
}

/*logger.debug("*** URL *** "+ request.getRequestURL());*/
logger.debug(request.getParameterMap()+ "*****HERE***");

try{


And the JSP:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@ page contentType="text/html;charset=windows-1252"%>
<%@page import="dod.af.usafa.camis.view.MajMinorappController"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="springform"%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252"/>
<title>Assign Major or Advisor</title>
<link rel="stylesheet" type="text/css" href="css/CAMIS.css"/>
<script type="text/javascript">
function mine() {

document.AssignMajMinor.submit();
}
</script>
</head>


<body>
<img src="images/MajorMinorManagement.gif" height="51" width="504"/>
<p align="center">
<a href="AssignMajMinor.do">Assign Major and Advisor</a>
<springform:form commandName="cadetList" method="post" name="AssignMajMinor">

<table id="tabela" cellspacing="1" >
<thead>
<tr>
<th width="25%" align="center"> Name </th>
<th width="5%" align="center"> Class Year </th>
<th width="5%" align="center"> Squad </th>
<th width="15%" align="left"> Current Major </th>
<th width="15%"> Current Advisor </th>
<th width="15%"> New Major </th>
<th width="4%"> </th>
</tr>
</thead>
</table>

<div style="height:300px; overflow:auto;">
<table id="tabelb" class="dataTable">
<thead> </thead>
<tbody>

<c:forEach items="${cadetList.pageList}" var="cadet" varStatus="idx">
<tr>
<td width="25%" align="left"> ${cadet.nameFull}</td>
<td width="5%" align="left"> ${cadet.classYr} </td>
<td width="5%" align="left"> ${cadet.squad} </td>
<td width="15%" align="left"> ${cadet.maj} </td>
<td width="15%"> ${cadet.advisor} </td>

<td width="15%">
<springform:form commandName="lst" id="row2" method="post" action="submit">
<select name="selected">
<option value="-1"> --Select--</option>
<c:forEach items="${lst}" var="mm" >
<option value="<c:out value="${mm.code}"/>"
<c:if test="${mm.code==status.value}"> selected="selected" </c:if>>
<c:out value="${mm.abbreviation}"/>
</option>
</c:forEach>
</select>
</springform:form>
</td>

<td width="1%" align="left"><input type="hidden" value="${cadet.pid}"></td>

</tr>
</c:forEach>
</tbody>
</table>
</div>
<form>
<input type="button" name="Save" value="Save" onclick="mine()" />
<input type="submit" name="Delete" value="Delete"/>
<input type="submit" name="Cancel" value="Cancel" onclick="document.AssignMajMinor.submit();"/>
</form>
</springform:form>

</body>
</html>

cwilkes
Jun 14th, 2007, 03:26 PM
Maybe I'm missing something but you didn't put "model" into your cadetList in formBackingObject. Did you mean to do that?

HaasHenry
Jun 14th, 2007, 03:34 PM
As i said I'm very new to this, but I thought that was what I was doing with the code:

model.put("cadetList", cadetList);
return cadetList


Could you suggest something else?

jglynn
Jun 14th, 2007, 04:51 PM
If you wish your hidden field values be bound then you need to explicitly specify that in the jsp.


<springform:hidden path="${pid}" />


However, I see a bigger issue in that you're generating a <form/> for each iteration of that loop. Is this really your intent?

cwilkes
Jun 16th, 2007, 01:15 AM
You don't have to put "cadetlist" into a Map as that's your command object and it is automatically put into the ModelAndView's Map. You're correctly referencing it with the <spring:form/> tag as well.

I'm not sure what you're trying to do with that form within a form. Can you post what you want your HTML to look like?

HaasHenry
Jun 18th, 2007, 09:00 AM
Thank you for the reply. Basically my form should be a table of names, and other data, with the last column being a drop-down. This combo box is the only updatable field on the form.

HaasHenry
Jun 19th, 2007, 10:33 AM
Thanks to all those that replied. I've removed some of the foolish things I was doing in my JSP.

I've included a snippit of the drop-down and then the awkward syntax trouble I was having with the hidden field. Obviously I was making things much more difficult then they needed to be. I'm learning.


<td width="15%">
<select name="selected">
<option value="-1"> --Select--</option>
<c:forEach items="${lst}" var="mm" >
<option value="<c:out value="${mm.code}"/>"
<c:if test="${mm.code==status.value}"> selected="selected" </c:if>>
<c:out value="${mm.abbreviation}"/>
</option>
</c:forEach>
</select>
</td>

<td>
<input type="hidden" id="pid" value="${cadet.pid}" name="pid"/>
</td>


Thank you again. Until next time...

jglynn
Jun 19th, 2007, 04:07 PM
Just as an FYI, you could achieve the same effect (and reduce the amount of code) using the Spring form tags.


<td width="15%">
<springform:select path="selected"
items="lst"
itemValue="code"
itemLabel="abbreviation"/>
</td>

<td>
<springform:hidden path="pid"/>
</td>