PDA

View Full Version : formpanel restful



mmwhw
20 Feb 2011, 6:12 PM
hi, everybody:
in my testing project, I used the spring3 in the server side and extjs3 in the client side, I want to use formpanel to submit data to server:

client code
var simple = new Ext.FormPanel({
labelWidth: 75, // label settings here cascade unless overridden
url:'account/new' (http://www.sencha.com/forum/'account/new'),
id:'accountForm',
frame:true,
title: 'Simple Form',
bodyStyle:'padding:5px 5px 0',
width: 350,
defaults: {width: 230},
defaultType: 'textfield',
items: [{
fieldLabel: 'Name',
name: 'name',
allowBlank:false
},{
fieldLabel: 'balance',
name: 'balance'
},{
fieldLabel: 'equityAllocation',
name: 'equityAllocation'
}, {
fieldLabel: 'renewalDate',
name: 'renewalDate',
}
],
buttons: [{
text: 'Save',
handler:function(){
var d=Ext.getCmp("accountForm");
if(d.getForm().isValid()){
d.getForm().submit({
restful:true,
waitMsg:"process....",
success:function(e,g){
Ext.ux.Toast.msg("msg","success?");

},
failure:function(e,f){
switch (f.failureType) {
case Ext.form.Action.CLIENT_INVALID:
Ext.Msg.alert('Failure', 'Form fields may not be submitted with invalid values');
break;
case Ext.form.Action.CONNECT_FAILURE:
Ext.Msg.alert('Failure', 'Ajax communication failed');
break;
case Ext.form.Action.SERVER_INVALID:
Ext.Msg.alert('Failure', f.result.msg);
}

}
});
}
}
},{
text: 'Cancel'
}]
});

server code:
@RequestMapping(value="/new")
public @ResponseBody Map<String, ? extends Object> create(@RequestBody Account account, HttpServletResponse response) {
Set<ConstraintViolation<Account>> failures = validator.validate(account);
if (!failures.isEmpty()) {
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
return validationMessages(failures);
} else {
accounts.put(account.assignId(), account);
return Collections.singletonMap("id", account.getId());
}
}

after I click save , firebug display:

post tab:

??application/x-www-form-urlencoded
balanceaequityAllocationanamearenewalDatea???
name=a&balance=a&equityAllocation=a&renewalDate=a


html tab:

HTTP Status 404 -

type Status report
message
description The requested resource () is not available.


can anybody tell me why, and how to realize the function?
thanks

mmwhw
20 Feb 2011, 10:47 PM
anybody know it ?:((

Condor
21 Feb 2011, 6:20 AM
Are you sure you've setup Spring correctly? A 404 error usually means that the server doesn't have a handler for that URL.

mmwhw
21 Feb 2011, 5:39 PM
I use spring sample mvc-ajax, so the spring is correct, and the sample use jquery to submit the data.

Grolubao
22 Feb 2011, 1:04 AM
We're also using Spring MVC. It seems to me a case that the mapping is not correct. I would suggest you use the <c:url tag to point to the right context.

Does your Controller have the @Controller annotation? Also make sure that your web.xml is redirecting you to the right servlet.

We don't use REST in your case, but it shouldn't differ that much...