PDA

View Full Version : when using <spring:bind> iam facing the problem


pdvprasad
Aug 8th, 2007, 08:53 AM
this is my jsp

<%@ include file="/common/taglibs.jsp"%>


<%@ taglib uri="/web/WEB-INF/pager-taglib.tld" prefix ="pg" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><title>Aikia - Discussion Forums </title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="styles/custom.css" rel="stylesheet" type="text/css">
</head>
<body>
<td valign="top" width="80%">
<form name="inputForm" method="post" action="comment.html" onsubmit="return validateUser(this)">
<fmt:message key="DiscussComment.userComment"/>

<div id="commentInputContainer">

<table border="0" cellpadding="0" cellspacing="0">
<tbody><tr>
<td rowspan="3" style="padding-right: 40px;">
<spring:bind path="DiscussComment.userComment">
<span class="fieldError"><cut value="${status.errorMessage}"/></span>
<input type="textarea" name="userComment" value="<cut value="${status.value}"/>" id="userComment" cols="55" rows="4"align="" class="text large"/>
</spring:bind>
</td>
</tr>
<tr>
<br>
<td valign="bottom">
<input type="submit" class="button" value="Post" />
</tr>
</tbody></table>
</td>
</tr>
<tr><td>&nbsp;</td></tr>
</tbody></table>
</div>
</form>
<br><br>
</html>
<script type="text/javascript" src="<c:url value="/scripts/validator.jsp"/>"></script>

rhis error is comming

javax.servlet.jsp.JspTagException: Neither Errors instance nor plain target object for bean name 'DiscussComment' available as request attribute
at org.springframework.web.servlet.tags.BindTag.doSta rtTagInternal(BindTag.java:118)
at org.springframework.web.servlet.tags.RequestContex tAwareTag.doStartTag(RequestContextAwareTag

DJViking
Aug 8th, 2007, 08:58 AM
Have you defined the name "DiscussComment" as the command name in the controller? setCommandName("DiscussComment");

Colin Yates
Aug 8th, 2007, 09:01 AM
You must include the Errors model in your ModelAndView for the form tags to work.

Can you post your Controller please.

pdvprasad
Aug 8th, 2007, 09:02 AM
i already declared like this way

public DisplayCommentsController() {
setCommandName("DiscussComment");
setCommandClass(DiscussBoard.class);

DJViking
Aug 8th, 2007, 09:09 AM
yatesco is right.

The following is need in showForm() method. At least in my case.
Map result = errors.getModel();
return new ModelAndView(getFormView(), result);

pdvprasad
Aug 8th, 2007, 09:17 AM
i written the controller class like this
package com.aikia.webapp.action;


import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.aikia.model.DiscussBoard;
import com.aikia.service.DiscussBoardManager;


import org.springframework.web.servlet.ModelAndView;

/**
* Controller class to upload Files.
*
* <p>
* <a href="FileUploadFormController.java.html"><i>View Source</i></a>
* </p>
*
* @author <a href="mailto:matt@raibledesigns.com">Matt Raible</a>
*/

public class DisplayCommentsController extends BaseFormController {
private DiscussBoardManager discussBoardManager;

/**
* @param discussBoardManager The discussBoardManager to set.
*/
public void setDiscussBoardManager(DiscussBoardManager discussBoardManager) {
this.discussBoardManager = discussBoardManager;
}

public DisplayCommentsController() {
setCommandName("DiscussComment");
setCommandClass(DiscussBoard.class);


}


public ModelAndView handleRequestInternal(HttpServletRequest request,HttpServletResponse response)throws Exception{

List l = discussBoardManager.getDiscussBoards();
return new ModelAndView("disc_forum","list",l);

}

}


where i add the showForm method

jglynn
Aug 8th, 2007, 10:11 AM
Typically you'd do something like this.


Map model = errors.getModel();
List l = discussBoardManager.getDiscussBoards();
model.put("list",l);
return new ModelAndView("disc_forum",model);


However handleRequestInternal does not make the BindException object "errors" available to you.
Have you read much about the controller workflow?

Colin Yates
Aug 8th, 2007, 10:28 AM
where i add the showForm method
I would suggest you use the SimpleFormController instead of BaseFormController.

If you still want to do it "by hand" so to speak, you need to:


ServletRequestDataBinder binder = new ServletRequestDataBinder(yourObject, "yourFormName");
modelAndView.addAll(binder.getBindingResult().getM odel());

Jörg Heinicke
Aug 9th, 2007, 11:39 PM
You must include the Errors model in your ModelAndView for the form tags to work.

Now that a Spring team member is following the forums more closely again I want to complain about this issue ;)

The above is really a major flaw in Spring MVC and triggers sooo many threads in this forum. Even when the people put the command object into the model by hand they still lack registered PropertyEditors.
Probably the Spring team is aware of this issue and works already on a solution ;)

Thanks for listening :)

Joerg