Results 1 to 4 of 4

Thread:

  1. #1
    Join Date
    Jan 2005
    Location
    Toronto, Canada
    Posts
    34

    Default
    Hi there folks,
    I am having the weirdest problem I have ever had with spring's tag.

    I have a page as follows:
    Code:
    					<spring&#58;bind path="command.numberOfCallbacks">
    					<tr> <%-- Number of call backs --%>
    						<td>
    							$&#123;status.value&#125;
    							<label for="numberOfCallbacks">Number of callbacks until start of interview&#58; </label>
    						</td>
    						<td>
    							<input type="text" name="$&#123;status.expression&#125;" id="numberOfCallbacks"
    								<c&#58;if test="$&#123;command.patientName==null || command.patientName==''&#125;">
    									disabled="disabled"
    								</c&#58;if>
    								<c&#58;if test="$&#123;status.value > 0&#125;">
    									value="$&#123;status.value&#125;"
    								</c&#58;if>
    							>
    						</td>
    						<td>
    							<span class="newInterview_error_messages"><c&#58;out value="$&#123;status.errorMessage&#125;"/></span>
    						</td>
    					</tr>
    					</spring&#58;bind>
    Here goes the command object:

    Code:
    /*
     * Created on Mar 21, 2005
     *
     */
    package xxxxxxxxxxxxx.xxxxxxxxxxxxxx.xxxxxxxxxxx.xxxxx;;
    
    import java.util.Date;
    
    /**
     * @author Erick
     * 
     */
    public class StartInterviewFormBean &#123;
    	
    	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&#40;&#41;&#123;
    		date = new Date&#40;&#41;;
    		interviewStartTime = new Date&#40;&#41;;
    	&#125;
    	
    	/**
    	 * @return Returns the date.
    	 */
    	public Date getDate&#40;&#41; &#123;
    		return date;
    	&#125;
    	
    	/**
    	 * @param date The date to set.
    	 */
    	public void setDate&#40;Date date&#41; &#123;
    		this.date = date;
    	&#125;
    	
    	/**
    	 * @return Returns the interviewStartTime.
    	 */
    	public Date getInterviewStartTime&#40;&#41; &#123;
    		return interviewStartTime;
    	&#125;
    	
    	/**
    	 * @param interviewStartTime The interviewStartTime to set.
    	 */
    	public void setInterviewStartTime&#40;Date interviewStartTime&#41; &#123;
    		this.interviewStartTime = interviewStartTime;
    	&#125;
    	
    	/**
    	 * @return Returns the studyId.
    	 */
    	public String getStudyId&#40;&#41; &#123;
    		return studyId;
    	&#125;
    	
    	/**
    	 * @param studyId The studyId to set.
    	 */
    	public void setStudyId&#40;String studyId&#41; &#123;
    		this.studyId = studyId;
    	&#125;
    	
    	/**
    	 * @return Returns the numberOfCallbacks.
    	 */
    	public int getNumberOfCallbacks&#40;&#41; &#123;
    		return numberOfCallbacks;
    	&#125;
    	
    	/**
    	 * @param numberOfCallbacks The numberOfCallbacks to set.
    	 */
    	public void setNumberOfCallbacks&#40;int numberOfCallbacks&#41; &#123;
    		this.numberOfCallbacks = numberOfCallbacks;
    	&#125;
    	
    	/**
    	 * @return Returns the caregiverName.
    	 */
    	public String getCaregiverName&#40;&#41; &#123;
    		return caregiverName;
    	&#125;
    	/**
    	 * @param caregiverName The caregiverName to set.
    	 */
    	public void setCaregiverName&#40;String caregiverName&#41; &#123;
    		this.caregiverName = caregiverName;
    	&#125;
    	/**
    	 * @return Returns the patientName.
    	 */
    	public String getPatientName&#40;&#41; &#123;
    		return patientName;
    	&#125;
    	/**
    	 * @param patientName The patientName to set.
    	 */
    	public void setPatientName&#40;String patientName&#41; &#123;
    		this.patientName = patientName;
    	&#125;
    	/**
    	 * @return Returns the caregiverPhoneNumber.
    	 */
    	public String getCaregiverPhoneNumber&#40;&#41; &#123;
    		return caregiverPhoneNumber;
    	&#125;
    	/**
    	 * @param caregiverPhoneNumber The caregiverPhoneNumber to set.
    	 */
    	public void setCaregiverPhoneNumber&#40;String caregiverPhoneNumber&#41; &#123;
    		this.caregiverPhoneNumber = caregiverPhoneNumber;
    	&#125;
    	/**
    	 * @return Returns the interviewTypeId.
    	 */
    	public int getInterviewTypeId&#40;&#41; &#123;
    		return interviewTypeId;
    	&#125;
    	/**
    	 * @param interviewTypeId The interviewTypeId to set.
    	 */
    	public void setInterviewTypeId&#40;int interviewTypeId&#41; &#123;
    		this.interviewTypeId = interviewTypeId;
    	&#125;
    	/**
    	 * @return Returns the caregiverId.
    	 */
    	public int getCaregiverId&#40;&#41; &#123;
    		return caregiverId;
    	&#125;
    	/**
    	 * @param caregiverId The caregiverId to set.
    	 */
    	public void setCaregiverId&#40;int caregiverId&#41; &#123;
    		this.caregiverId = caregiverId;
    	&#125;
    	/**
    	 * @return Returns the action.
    	 */
    	public String getAction&#40;&#41; &#123;
    		return action;
    	&#125;
    	/**
    	 * @param action The action to set.
    	 */
    	public void setAction&#40;String action&#41; &#123;
    		this.action = action;
    	&#125;
    &#125;
    As you can see, numberOfCallbacks is of type int.
    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:
    Code:
    								<c&#58;if test="$&#123;status.value > 0&#125;">
    									value="$&#123;status.value&#125;"
    								</c&#58;if>
    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.

    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
    Erick Dovale


  2. #2
    Join Date
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,104

    Default

    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
    When a type mismatch occurs, status.value needs to be a string to re-display the failed input. You have to add an extra test around your ${status.value > 0}. E.g. ${status.value.class.name ne 'java.lang.String'}

  3. #3
    Join Date
    Jan 2005
    Location
    Toronto, Canada
    Posts
    34

    Default

    Thanks katentim,
    testing for the class will certainly do the trick however, how is possible that in other many numeric fields I have in my applicatino this does not happens??

    Thanks.
    Erick Dovale

  4. #4
    Join Date
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,104

    Default

    is possible that in other many numeric fields I have in my applicatino this does not happens??
    I don't think so. You should at least test that the type matches before doing further processing dependent on user input. Maybe a better test is ${status.errors.errorCount eq 0}. If this is true then the input has passed validation and is safe to use.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •