[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

09/23/2009 at 03:07PM PDT, ID: 24756755 | Points: 250
[x]
Attachment Details

Using JSON to Serialize from JSP to JavaScript

Asked by WashoeCounty in Java Programming Language, Java Server Pages (JSP), JSON

Tags: Java, jsp, JavaScript, JSON, Serialize, dojo

I am using JSON to serialize a Java object so I can use it in a JavaScript file.  I am also using dojo, as you can see below.  

Sometimes I get an object error when I am trying to access the serialized parts of the object in the JavaScript file.  What would cause these type of errors?  I have used serializer.serialize and serializer.deepSerialize based on whether or not the object contains more objects.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
//In the js
function loadControls(projectsId){
   dojo.xhrGet( {
      url: "ProjectsTools.jsp?action=getProjectByProjectsId&projectsId="+projectsId,
      handleAs: "json",
      sync: true,
       timeout: 5000, 
      load: function(response, ioArgs) {
          document.getElementById("projectName").value = response.projectName;
      },
      error: function(response, ioArgs) {
         return response;
      }
   });
}
 
//In the JSP
if (action.equals("getProjectByProjectsId")){
   Integer projectsId = Integer.parseInt(request.getParameter("projectsId"));
   projects = projectsManager.getProjectByProjectsId(projectsId);
   JSONSerializer serializer = new JSONSerializer();
   out.println(serializer.deepSerialize(projects));
}
[+][-]09/24/09 03:11 AM, ID: 25411551

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/24/09 06:44 AM, ID: 25413255

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-91 - Hierarchy / EE_QW_3_20080625