0 Replies Latest reply on Sep 9, 2011 10:43 AM by m beedub

    Having trouble accessing serialized data on jsFunction return

    m beedub Newbie

      Hi

       

      The following code doesn't seem to work correctly.

       

      Java:

                public JSONObject getJsonResults()
                {
                          JSONObject dataToJSON = new JSONObject();
                       try
                          {
                                    dataToJSON.put("property1", "green");
                                    dataToJSON.put("property2", "blue");
                          }
                          catch (JSONException e)
                          {
                       //TODO Implement appropriate exception handling
                                    e.printStackTrace();
                          }
                          return dataToJSON;
                }
      
      

       

       

      xhtml:

       

        <a4j:jsFunction name="ajsJSONajax"
             data="#{BSMgr.getJsonResults()}"
             oncomplete="alert(data);alert(data.property1);">
        </a4j:jsFunction>
      
        <h:graphicImage value="/img/clickme.png" onclick="ajsJSONajax();" />
      
      

       

      The click on the image calls the a4j function which gets the JSON data from the backing bean.

       

      Contents of dataToJSON that get returned are:

       

      {"property2":"blue","property1":"green"}
      

       

       

      The first alert returns

       

      [object Object]

       

      which is expected.

       

      The second alert returns

       

      undefined

       

      It's the last one that's the issue - I want to be able to get to the contents of property1.

       

      Is there something wrong with the code above?

       

      Thanks