[Building Sakai] EntityBroker and posting JSON

Adrian Fish a.fish at lancaster.ac.uk
Fri Feb 5 03:23:38 PST 2010


Hi Lovemore,

Thanks a bunch for replying so quickly. Do you have to setup keys in the 
json for every field in your POJO, even if the values are empty?

Cheers,

Adrian.

Lovemore Nalube wrote:
> Dear Adrian
>  
> Yes it is possible and very easy too!
> Your jQuery code seems to work, though you do not need the .json in 
> the url and the dataType in this case is not necessary as well. A 
> meaningful error reason will come from xmlHttpRequest.statustext as 
> that will return the error headers eg: Forbidden (403).
>  
> On the EntityProvider side, you will need to do the following (in this 
> example SmsAccount is a POJO):
> 1. specify a public Object getSampleEntity() that returns new SmsAccount()
> 2. in createEntity ensure you have: SmsAccount smsAccount = 
> (SmsAccount) entity; //entity in this case entity is the createEntity 
> method parameter.
> 3. throw appropriate service/validation errors in createEntity so that 
> the jQuery code can respond appropriately.
>  
> That's it. Make sure the parameter names (ie object keys in jsonData) 
> are the same as in your POJO definition.
>  
> :)
>  
> --
> Lovemore Nalube
> Online Learning Environments Developer (Vula)
> PASS Transformation Committee REP
> Centre for Educational Technology
> CHED
> University of Cape Town
> www.cet.uct.ac.za
>
> /* Work Email: lovemore.nalube at uct.ac.za
> /* Cell: 076 186 1244
> /* GTalk: lovenalube at gmail.com
>
>
> >>> On 05/02/2010 at 12:47, in message 
> <4B6BF72E.6050702 at lancaster.ac.uk>, Adrian Fish 
> <a.fish at lancaster.ac.uk> wrote:
> Can you post  a json string to the EB direct handler and have it decoded
> into a POJO? Anybody know ? I was hoping to be able to post JSON to EB
> with code like this:
>
> jQuery.ajax(
>         {
>             url : "/direct/bbb-meeting/new.json",
>             dataType : "text",
>             type : 'POST',
>             data : jsonData,
>             success : function(meeting)
>             {
>                 switchState('currentMeetings');
>             },
>             error : function(xmlHttpRequest,status,error)
>             {
>                 alert("Failed to create meeting. Reason: " + error);
>             }
>         });
>
> ... but am having no success. The entity in my createEntity method is
> uninitialised.
>
> Any ideas? Anyone?
>
> Thanks,
>
> Adrian.
>
> -- 
> ==================================
> Adrian Fish
> Software Engineer
> Centre for e-Science
> Bowland Tower South C Floor
> Lancaster University
> Lancaster
> LA1 4YW
> email: a.fish at lancaster.ac.uk
>
> http://confluence.sakaiproject.org/display/YAFT/Yaft
> http://confluence.sakaiproject.org/display/BLOG/Home
> http://confluence.sakaiproject.org/display/AGORA/Home
>

-- 
==================================
Adrian Fish
Software Engineer
Centre for e-Science
Bowland Tower South C Floor
Lancaster University
Lancaster
LA1 4YW
email: a.fish at lancaster.ac.uk

http://confluence.sakaiproject.org/display/YAFT/Yaft
http://confluence.sakaiproject.org/display/BLOG/Home
http://confluence.sakaiproject.org/display/AGORA/Home

-------------- next part --------------
A non-text attachment was scrubbed...
Name: a_fish.vcf
Type: text/x-vcard
Size: 289 bytes
Desc: not available
Url : http://collab.sakaiproject.org/pipermail/sakai-dev/attachments/20100205/b43c5f51/attachment.vcf 


More information about the sakai-dev mailing list