ClientContextLibrary

From Gcube Wiki
Revision as of 14:22, 5 November 2016 by Costantino.perciante (Talk | contribs) (Created page with "__TOC__ =Client Context for gCube Portlets = Starting from '''gCube 4.2''', a new mechanism to retrieve the current user identifier and the current context identifier at clie...")

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Client Context for gCube Portlets

Starting from gCube 4.2, a new mechanism to retrieve the current user identifier and the current context identifier at client side has been introduced for gCube's portlets. The Client Context library allows to easily retrieve these information by relying on the Liferay.ThemeDisplay javascript object [1], and inject them at server side (they are transparently sent along the header of the remote requests). At server side, you should use the PortalManager library[2], to retrieve and convert them automatically to the current user's username and gCube context.

The Client Context Widget

The Client Context has been developed as a GWT Widget. Its source code is available in the gCube SVN repository, at this url. Basically, it offers two self-explanatory methods

public static native String getCurrentContextId();

and

public static native String getCurrentUserId();

This code is translated as native Javascript code, starting from pure Java code by the GWT Framework. Please note that both methods actually returns a number value.

To use the widget, you need to declare the following maven dependency in your project's pom.xml

<dependency>
        <groupId>org.gcube.portal</groupId>
	<artifactId>client-context-library</artifactId>
	<version>[1.0.0-SNAPSHOT,)</version>
	<scope>compile</scope>
</dependency>

as well as the following line in the gwt.xml file of your gwt-portlet:

<!--Inherit the GCubeClientContext widget code -->
<inherits name='org.gcube.portal.clientcontext.GCubeClientContext' />

Finally, in the onModuleLoad() method of your gwt web application, you must declare the following code line

public class ... implements EntryPoint {
 
  public void onModuleLoad() {
 
     /**
      * Inject client context to automatically pass the context id and the user id to the server side 
      */
      GCubeClientContext.injectContext();
 
      ...
   }	  
 }

Portlet Example

A portlet example's source code is available [here url] It uses the both the Client Context library and the PortalManager one, together with the UserManagementLibrary, which abstracts Liferay's concepts and map them to gCube's ones.


Tips for Development Environments

  1. Liferay is the portal technology adopted in the D4Science Infrastructure which is built upon the gCube software
  2. More information about the PortalManager are reported here