Hi there folks,
I am having the weirdest problem I have ever had with spring's tag.
I have a page as follows:
Here goes the command object:Code:<spring:bind path="command.numberOfCallbacks"> <tr> <%-- Number of call backs --%> <td> ${status.value} <label for="numberOfCallbacks">Number of callbacks until start of interview: </label> </td> <td> <input type="text" name="${status.expression}" id="numberOfCallbacks" <c:if test="${command.patientName==null || command.patientName==''}"> disabled="disabled" </c:if> <c:if test="${status.value > 0}"> value="${status.value}" </c:if> > </td> <td> <span class="newInterview_error_messages"><c:out value="${status.errorMessage}"/></span> </td> </tr> </spring:bind>
As you can see, numberOfCallbacks is of type int.Code:/* * Created on Mar 21, 2005 * */ package xxxxxxxxxxxxx.xxxxxxxxxxxxxx.xxxxxxxxxxx.xxxxx;; import java.util.Date; /** * @author Erick * */ public class StartInterviewFormBean { public final static int DEFAUL_INTERVIEW_ID = -999; public final static int NEW_CAREGIVER = -5555; public final static int DEFAULT_CAREGIVER_ID = -999; private Date date; private String studyId; private String patientName; private int caregiverId = DEFAULT_CAREGIVER_ID; private String caregiverName; private String caregiverPhoneNumber; private int interviewTypeId; private Date interviewStartTime; private int numberOfCallbacks; private String action; /** * Default contructor. * Initializes all the inner objects. * */ public StartInterviewFormBean(){ date = new Date(); interviewStartTime = new Date(); } /** * @return Returns the date. */ public Date getDate() { return date; } /** * @param date The date to set. */ public void setDate(Date date) { this.date = date; } /** * @return Returns the interviewStartTime. */ public Date getInterviewStartTime() { return interviewStartTime; } /** * @param interviewStartTime The interviewStartTime to set. */ public void setInterviewStartTime(Date interviewStartTime) { this.interviewStartTime = interviewStartTime; } /** * @return Returns the studyId. */ public String getStudyId() { return studyId; } /** * @param studyId The studyId to set. */ public void setStudyId(String studyId) { this.studyId = studyId; } /** * @return Returns the numberOfCallbacks. */ public int getNumberOfCallbacks() { return numberOfCallbacks; } /** * @param numberOfCallbacks The numberOfCallbacks to set. */ public void setNumberOfCallbacks(int numberOfCallbacks) { this.numberOfCallbacks = numberOfCallbacks; } /** * @return Returns the caregiverName. */ public String getCaregiverName() { return caregiverName; } /** * @param caregiverName The caregiverName to set. */ public void setCaregiverName(String caregiverName) { this.caregiverName = caregiverName; } /** * @return Returns the patientName. */ public String getPatientName() { return patientName; } /** * @param patientName The patientName to set. */ public void setPatientName(String patientName) { this.patientName = patientName; } /** * @return Returns the caregiverPhoneNumber. */ public String getCaregiverPhoneNumber() { return caregiverPhoneNumber; } /** * @param caregiverPhoneNumber The caregiverPhoneNumber to set. */ public void setCaregiverPhoneNumber(String caregiverPhoneNumber) { this.caregiverPhoneNumber = caregiverPhoneNumber; } /** * @return Returns the interviewTypeId. */ public int getInterviewTypeId() { return interviewTypeId; } /** * @param interviewTypeId The interviewTypeId to set. */ public void setInterviewTypeId(int interviewTypeId) { this.interviewTypeId = interviewTypeId; } /** * @return Returns the caregiverId. */ public int getCaregiverId() { return caregiverId; } /** * @param caregiverId The caregiverId to set. */ public void setCaregiverId(int caregiverId) { this.caregiverId = caregiverId; } /** * @return Returns the action. */ public String getAction() { return action; } /** * @param action The action to set. */ public void setAction(String action) { this.action = action; } }
The problem I am having is when I type some characters into he input (not a number). When the form is submited I am able to validate it; as expected I get a binding error which is properly added to the errors instance. But, when the view is rendered again I got a exception saying that it was not possible to covert a string value to a long value.
The error is happening right in this section of code:
And the reason for the error is that, although command.numberOfCallbacks is an int, ${status.value} is evaluating to the string I am entering in this field.Code:<c:if test="${status.value > 0}"> value="${status.value}" </c:if>
I have many other fields where an int is expected and when a string is entered the validator is able to fix the problem and when rendering ${status.value} evaluates to the value in the command bean. In this case I know I am doing something wrong but so far I have been unable to find it.
If any one can look at it and give a hint as to what could be happening I will appreciate it a lot.
Thanks


Reply With Quote