PDA

View Full Version : Validation Message not appear on Statusbar



ngjiajun
7 Jan 2013, 10:02 PM
hi, i have some doubts on the validation message not standardize on the statusbar not sure


whether i code the correct way or the methods i pass is correct.

for example: if empty fields submit, the validation error message will appear but however when i come to error message reply form the controller the error message is not standard as the empty fields submit.

therefore need some helps on how to edit it to standard the message.


currently my html page are as follow



html><head> <title>Hello Ext</title> <link rel="stylesheet" type="text/css" href="extjs/resources/css/ext-all.css"> <link rel="stylesheet" type="text/css"
href="extjs/examples/ux/statusbar/css/statusbar.css"> <script type="text/javascript" src="extjs/ext-all.js"></script> <script type="text/javascript"> var statusbarmsg = "${status}"; if (statusbarmsg == null || statusbarmsg =="") statusbarmsg = "Form Ready"; </script> <script type="text/javascript" src="app.js"></script> <script type="text/javascript" src="extjs/examples/ux/statusbar/StatusBar.js"></script></head><body></body></html>




my app.js as follow




Ext.require([
'Ext.form.*',
'Ext.tip.*'
]);

Ext.onReady(function() {
Ext.QuickTips.init();


var form = Ext.create('Ext.form.Panel', {
id:'frm',
defaults: {
xtype: 'textfield',
anchor: '100%',
},items: [{
xtype: 'textfield',
fieldLabel: 'Email',
name: 'email',

},{
xtype: 'textfield',
fieldLabel: 'Password',
name: password

}],
buttons: [{

text: 'Submit',
handler: fnLogin },{
text: 'Reset',
handler: function() {
form.getForm().reset();
}
}]
});


function fnLogin(){
Ext.getCmp('frm').on({
beforeaction: function(){
Ext.getCmp('win').body.mask();
Ext.getCmp('sbWin').showBusy();
}
});
frm.getForm().submit({
commandName: 'login', //this will call LoginController.java
standardSubmit: true.
method:'POST',
success: function(){
Ext.getCmp('win').body.unmask();
Ext.getCmp('sbWin').setStatus({
text:'Login successfully!',
iconCls:'x-status-valid' // this does not appear
});
},


failure: function(form,action){
// this failure function does not appear at all
Ext.getCmp('win').body.unmask();
if (action.failureType == 'server'){
obj = Ext.util.JSON.decode(action.response.responseText);
Ext.getCmp('sbWin').setStatus({
text: obj.errors.reason,
iconCls:'x-status-error'
});
}
else {
if (typeof(action.response)== 'undefined'){
Ext.getCmp('sbWin').setStatus({
text: obj.errors.reason,
iconCls:'x-status-error'
});
}
else {
Ext.Msg.alert('Warning', 'Server is unreachable: ' + action.response.responseText);
}
}
}
});

}


Ext.create('Ext.window.Window', {
bodyPadding: 5,
closable: false,
resizable: false,
title: 'Login',
id:'win',
width: 325,
listeners: {
afterrender: function(component, eOpts) {
Ext.EventManager.onWindowResize(component.center, component)
},
beforeclose: function(component, eOpts) {
Ext.EventManager.removeResizeListener(component.center, component);
}
},
items: [addUserForm],
bbar: new Ext.ux.StatusBar({
text:status,
id:'sbWin',
iconCls:'x-status-saved'
})
}).show();




});



my login controller is as below








package login.controller;


import model.User;
import java.servlet.ServletException;
import java.servlet.http.HttpServletRequest;
import java.servlet.http.HttpServletResponse;
import java.servlet.http.HttpSession;
import org.springframework.validation.BindException;
import org.springframework.validation.Errors;
import org.springframework.validation.Validator;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;
import org.springframework.web.servlet.view.RedirectView;






public class LoginFormController extends SimpleFormController {


@Override
protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws Exception {
User login = (User) command;
String loginId = login.getLoginId();
String pwd = login.getPassword();

if (loginId == null || loginId.length() == 0) {
request.setAttribute("wrongUser",loginId);
ModelAndView mav = ModelAndView("login.htm");
mav.addObject("sbWin","Enter userid");
return mav;
}
else if (pwd == null || pwd.length() == 0) {
request.setAttribute("wrongUser",loginId);
ModelAndView mav = ModelAndView("login.htm");
mav.addObject("sbWin","Enter password");
return mav;
}
else {

if (loginId="admin" && pwd ="123"){
HttpSession session = request.getSession();
session - request.getSession(true);
request.setAttribute("loggedAccount",session.getId());
ModelAndView mav = ModelAndView("user.htm");
mav.addObject("loginId", loginId);
return mav;
}
else {
request.setAttribute("wrongUser",loginId);
ModelAndView mav = ModelAndView("login.htm");
mav.addObject("sbWin","Enter userId and password");
return mav;
}
}
}




}

mitchellsimoens
10 Jan 2013, 9:50 AM
Have you set a breakpoint to follow the code? Any errors?