Announcement Announcement Module
Collapse
No announcement yet.
Strange Error Text Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Strange Error Text

    My login screen shows characters where my errors should be. This happens on the GET request and on POST, so on first page load and on login failure. The message text is contained within properties files defined in the message source bean and I can pull the error messages from the file.

    Thanks for any help.

    My jsp code is below. The taglibs are imported correctly, because the i18n messages display and I verified the c:outs:
    Code:
    <html>
    	<body>	
    		<form method="POST" action="/login.do">
    			<table>
    				<spring&#58;bind path="command.*"> 
    			 * ** *<c&#58;forEach items="$&#123;status.errorMessages&#125;" var="errorMessage"> 
    			 		<tr><td>
    			 * ** ** *<c&#58;out value="$&#123;errorMessage&#125;"/>
    			 		</tr></td>
    			 * ** *</c&#58;forEach> 
     * *				</spring&#58;bind> 
    				<tr>
    					<td class="label">
    						<spring&#58;message code="username"/>
    					</td>
    					<td>
    						<spring&#58;bind path="command.username">
    							<input class="input" type="text" name="username"/>
    						</spring&#58;bind>
    					</td>
    				</tr>
    				<tr>
    					<td class="label">
    						<spring&#58;message code="password"/>
    					</td>
    					<td>
    						<spring&#58;bind path="command.password">
    							<input type="password" class="input" name="password"/>
    						</spring&#58;bind>
    					</td>
    					<td>
    						<input class="button" type="submit" value="<spring&#58;message code='login'/>"/>
    					</td>
    				<tr>
    			</table>
    		</form>
    	</body>
    </html>
    This is my login controller
    Code:
    protected Object formBackingObject&#40;HttpServletRequest request&#41; throws ServletException &#123; 
        		return new User&#40;&#41;;
        &#125; 
        
        protected ModelAndView onSubmit&#40;HttpServletRequest q_,  HttpServletResponse r_,  Object f_,  BindException e_&#41;&#123; 
            User _user = &#40;User&#41;f_;
            String message = getApplicationContext&#40;&#41;.getMessage&#40;"required.username", null, "My Default Message", q_.getLocale&#40;&#41;&#41;;
            boolean _validated = _userService.validateUser&#40;_user.getUsername&#40;&#41;, _user.getPassword&#40;&#41;&#41;;
            if &#40;_validated&#41;&#123;
            		return new ModelAndView&#40;getSuccessView&#40;&#41;,"user", _user&#41;;
            &#125;
            else&#123;
            		return new ModelAndView&#40;getFormView&#40;&#41;, e_.getModel&#40;&#41;&#41;;
            &#125;
            
        &#125;
    And the validator

    Code:
    public class LoginValidator implements Validator &#123;
    	
    	private Logger _logger = Logger.getLogger&#40;LoginValidator.class&#41;;
    
    	public boolean supports&#40;Class clazz_&#41; &#123;
    		return clazz_.equals&#40;User.class&#41;;
    	&#125;
    
    	public void validate&#40;Object obj_, Errors errors_&#41; &#123;
    		System.out.println&#40;"validating"&#41;;
    		User _user = &#40;User&#41; obj_;
    		ValidationUtils.rejectIfEmpty&#40;errors_, "username", "required.username", "Username is required"&#41;;
    	&#125;
    
    &#125;

  • #2
    I'm a newbie so I don't know if the way I'm doing it is any better but here's how I'm doing it. Here's the controller part from my -servlet.xml file:
    Code:
        <bean id="adminSignInCtlr" class="ctlr.AdminSignInCtlr">
            <property name="commandClass" value="view.AdminSignInFrmData" />
            <property name="validator" ref="adminSignInValidate" />
            <property name="formView" value="adminSignInView" />
            <property name="adminView" value="fdebugView" />
            <property name="waitlistView" value="waitlistView" />
            <property name="sessionForm" value="false" />
            <property name="bindOnNewForm" value="true" />
            <property name="facilityDao" ref="facilityDao" />
            <property name="wleDao" ref="wleDao" />
        </bean>
    For my controller the onSubmit is:
    Code:
        protected ModelAndView
        onSubmit&#40;Object cmd&#41; &#123;
            AdminSignInFrmData      sifd = &#40;AdminSignInFrmData&#41; cmd;
    
            String view = sifd.getView&#40;&#41;;
    
            Map<String,Object> model = new HashMap<String, Object>&#40;&#41;;
            model.put&#40;"sifd", sifd&#41;;
            model.put&#40;"platcnt", facilityDao.getPlatCount&#40;sifd.getFacility&#40;&#41;&#41;&#41;;
            model.put&#40;"wlePc", wleDao.getWaitlistEntries&#40;sifd.getFacility&#40;&#41;, "pc"&#41;&#41;;
            model.put&#40;"wleMac",wleDao.getWaitlistEntries&#40;sifd.getFacility&#40;&#41;,mac"&#41;&#41;;
    
            if &#40;view.equals&#40;"admin"&#41;&#41;
                return&#40;new ModelAndView&#40;adminView, "model", model&#41;&#41;;
    
            if &#40;view.equals&#40;"waitlist"&#41;&#41;
                return&#40;new ModelAndView&#40;waitlistView, "model", model&#41;&#41;;
    
            /* oops */
            return&#40;new ModelAndView&#40;&#40;String&#41; null, "model", model&#41;&#41;;
        &#125;
    And my validator is just like yours:
    Code:
        public void
        validate&#40;Object obj, Errors errs&#41; &#123;
            ValidationUtils.rejectIfEmpty&#40;errs,
                                    "facility",
                                    "err.facility",
                                    "Facility?"&#41;;
    
            ValidationUtils.rejectIfEmpty&#40;errs,
                                    "view",
                                    "err.view",
                                    "View?"&#41;;
    
            ValidationUtils.rejectIfEmptyOrWhitespace&#40;errs,
                                    "password",
                                    "err.password",
                                    "Password?"&#41;;
        &#125;
    I think that the main difference is that I'm setting the validator in the -servlet.xml file and not calling it directly the way you are and it's being called automatically for me.

    Comment

    Working...
    X