Sun Glassfish SocialSite Developer's Guide

Adding the SocialSite Widgets to the Host Application

Here is an sample of what a host application may include in its source code to add a SocialSite widget (profile.jsp):

01: <html>
02:  <head> 
03:   <script type="text/javascript" src="http://socialsite.example.com/js/consumer.jsp"></script>
04:   <script type="text/javascript">
05:    socialsite.setContext({
06:      'attributes': {
07:        'ownerId': '${ownerProfile.userId}'
08:      },
09:      'delegate': {
10:        'method': 'GET',
11:        'url': '&lt;%=request.getContextPath()%>/socialsite_context.jsp',
12:        'headers': {
13:          'cookie': document.cookie
14:        }
15:      }
16:    });
17:   <script>
18:  <head>
19:  <body>
20:   <script type="text/javascript">socialsite.addGadget({'spec':'http://example.com/gadget.xml'});</script>
21:   <script type="text/javascript">socialsite.addGadgets({'collection':'PROFILE'});</script>
22:  </body>
23: </html

Line 03 

The host application pulls in the necessary JavaScript code from the SocialSite software. 

Lines 04-17 

The host application directs the SocialSite software how to determine user context for the widgets. In the above example, the "delegate" entry tells the Social Server that it should makes its own HTTP GET request to another server-side URL ("socialsite_context.jsp" on the consumer site) to look up context settings. 

Lines 20 and 21 

The host application adds widgets to a page. This can either be done by explicitly referencing a widget's URL (as shown in line 20) or by referencing an identifier that should key into a collection of gadget instances that is known to the SocialSite software (as shown on line 21).