PDA

View Full Version : uncaught exception: [object Object] after a form submission



flamant
10 Mar 2011, 10:34 AM
Hi,
I have a form that I submit. When I inspect firebug console I can see that the request is sent to the server with the following response


{"resultingId":"KEYUSER3","success":true}

But there is immediately after in firebug console the following error message :



uncaught exception: [object Object]


here is the submited form request:



handler: function() {
var form = Ext.getCmp('addSignatureForm').getForm();
var actionUrl = "<c:url value="/secure/updateProtocolSignature.htm"/>";
var waitingMessage = '<spring:message code="application.updatingSignature"/>';
var failureMessage = '<spring:message code="application.failure.updatingSignature"/>';
var successMessage = '<spring:message code="application.success.updatingSignature"/>'

form.submit({
url:actionUrl,
waitMsg: waitingMessage,
success: function(form, action) {
Ext.getCmp("centerSearch").store.baseParams = { protocolId: protocolId, query: '' };
Ext.getCmp("centerSearch").store.load();
Ext.getCmp("subjectTreeView").root.setText(alias);
winAddSignature.close();

},
failure: function (result, action) {
Ext.Msg.alert('<spring:message code="application.failure"/>', failureMessage);
winAddSignature.close();

}
})
}


There is no error on the server side

And the strange thing is that 'success' and 'failure' handler are not fired

Thank you in advance for your answers

walldorff
11 Mar 2011, 4:31 PM
What does the POST say in Firebug? Maybe you can build in some logic in your server side code to reveal what the problem can be, i.e. what causes the exception.

flamant
12 Mar 2011, 2:52 AM
Hi walldorff and thank you for your answer,

Actually firebug indicates that the request is completed : params are correct, and I gave the response in the initial post. The request is not in red (indicating that there is no error)

Furthermore on the server side I already used multiple times the answer view without error.

Anyway I can give you the code on the server side (in JAVA):



StringBuffer sb = new StringBuffer();
if (callback != null) {
sb.append(callback);
sb.append("(");
}
JSONObject resp = new JSONObject();
resp.put("success", results.size() == 0 || (results.size() == 1 && results.get(0).getFieldId().equalsIgnoreCase("success")));
boolean errorMessage = false;
if (results.size() > 0) {
Iterator resultIt = results.iterator();
Result result;
while (resultIt.hasNext() && !errorMessage) {
result = (Result) resultIt.next();
if (!result.getFieldId().equalsIgnoreCase("success")) {
resp.put("message", result.getErrorMessage());
errorMessage = true;
}
}
}

if (results.size() == 1 && results.get(0).getFieldId().equalsIgnoreCase("success")) {
resp.put("resultingId", results.get(0).getDescription());
}

if (messageErrors.size() > 0) {
resp.put("errors", messageErrors);
}
sb.append(resp.toString());
if (callback != null)
sb.append(");");
logger.debug(sb);
response.setContentType("text/javascript; charset=utf-8");
response.getWriter().write(sb.toString());

I forgot to say that the waiting message is running indefitively
Thank you again

walldorff
12 Mar 2011, 3:42 AM
uncaught exception:
[object Object] <=== is a string, not an object.
So I think the object has been transformed into a string by your server side function:

response.getWriter().write(sb.toString());
Unfortunately I don't master Java, but what I do in such cases is checking the server side code from the ground up, starting with 1 simple hard coded response, expanding this code step by step and gradually replacing the hard coded data with variables, until I get the exception.

What happens if you comment out the last 2 lines or when you omit the .toString()?

flamant
12 Mar 2011, 5:56 AM
I tried



response.getOutputStream().write(sb.toString().getBytes());


and it worked

Thank you again