Difference between revisions of "Developing gCube Portlets Guide"

From Gcube Wiki
Jump to: navigation, search
m
Line 8: Line 8:
 
* IDE: Eclipse Java EE IDE for Web Developers. Version: 3.7+  
 
* IDE: Eclipse Java EE IDE for Web Developers. Version: 3.7+  
 
* Google Eclipse Plugin [GECLIPSE] (If you want your portlet to use GWT) [http://code.google.com/webtoolkit/download.html get GECLIPSE]
 
* Google Eclipse Plugin [GECLIPSE] (If you want your portlet to use GWT) [http://code.google.com/webtoolkit/download.html get GECLIPSE]
** GWT 2.4.0 (Bundled with the above Plugin)
+
** GWT 2.7.0 (Bundled with the above Plugin)
  
  
Line 195: Line 195:
 
</source>
 
</source>
 
----
 
----
 +
 +
== Migrating from Liferay 6.0 to Liferay 6.2.5 ==
 +
 +
* DTD
 +
* Portlet descriptors
 +
* web.xml - > sevlet 3.0
 +
 +
=== UsersManagement Library 2.0 ===
 +
 +
VRE, VO e RootVO are modelled as Sites (Not Organisations anymore)
 +
 +
* Usage of Liferay API Directly is forbidden
 +
* UserModel -> GCubeUser, e role e group
 +
 +
=== PortalManger 2.0 ===
 +
 +
** gateway name & URL
 +
** mail sender
 +
** infrastructure name
 +
 +
<source lang=java">
 +
int i = 0;
 +
</source>
 +
 +
=== ASL Social 1.0 ===
 +
 +
** public ApplicationNotificationsManager(HttpServletRequest request, String scope, SocialNetworkingUser currUser)
  
 
== Troubleshooting ==
 
== Troubleshooting ==
Line 209: Line 236:
  
 
''' Solution: ''' : Go to your Project Properties > Order and Export and make sure GWT SDK is listed before Tomcat one
 
''' Solution: ''' : Go to your Project Properties > Order and Export and make sure GWT SDK is listed before Tomcat one
 +
 +
 +
* Facet 3.0

Revision as of 11:16, 2 May 2016

Development of a gCube Portlet (GWT and Portlet)

Prerequisites

  • IDE: Eclipse Java EE IDE for Web Developers. Version: 3.7+
  • Google Eclipse Plugin [GECLIPSE] (If you want your portlet to use GWT) get GECLIPSE
    • GWT 2.7.0 (Bundled with the above Plugin)


Writing a GWT application

You can find useful information about how to write a gwt application on the Google Web Toolkit's official site: http://code.google.com/webtoolkit/.

! IMPORTANT INFO

In the entrypoint-class, in the onModuleLoad() method: When you are about to add your widget in the main page,
instead of writing:

RootPanel.get().add(<your widget>);

you must write:

RootPanel.get(<a unique id for the DIV>).add(<your widget>);

So, the generated html will be placed in the predefined div instead of being placed in an unspecified location.


Adapting your Portlet to Liferay Portal

gCube as chosen to move to Liferay Portal from its 1.9 release. In order to make your portlet be deployable on Liferay you need to add some Liferay Portal specific deployment descriptor xml and property files. (In addition to the standard one for portlets, the portlet.xml)

Create two empty xml files into your project war WEB-INF folder and name them

  • liferay-portlet.xml
  • liferay-display.xml

Create 1 empty property file into your project war WEB-INF folder and name it

  • liferay-plugin-package.properties

Content for the above files

<MyGCubePortletName> has to be changed with your actual portlet name

  • liferay-portlet.xml

The elements that should be placed in that file must follow the exact order ... ...

<?xml version="1.0"?>
<liferay-portlet-app>
	<portlet>
		<portlet-name><MyGCubePortletName></portlet-name>
		<layout-cacheable>false</layout-cacheable> <b>//for loading the new portlet</b>
		<instanceable>false</instanceable>    <b>//to use one portlet instance for the D4S portal</b>
		<ajaxable>false</ajaxable>  <b>//it is need for the correct rendering of the GWT portlet</b>
		<!-- LOCATION CSS HERE -->
                 <header-portlet-css>/css/test.css</header-portlet-css>
	</portlet>
	<role-mapper>
		<role-name>administrator</role-name>
		<role-link>Administrator</role-link>
	</role-mapper>
</liferay-portlet-app>

... ...


  • liferay-display.xml

The element 'category' is recommended to use the name "gCube Applications"

<?xml version="1.0"?>
<!DOCTYPE display PUBLIC "-//Liferay//DTD Display 5.2.0//EN" "http://www.liferay.com/dtd/liferay-display_5_2_0.dtd">
   <display>
      <category name="gCube Applications">
         <portlet id="<MyGCubePortletName>" />
      </category>
   </display>

  • liferay-plugin-package.properties
name=<MyGCubePortletName>
module-group-id=liferay
module-incremental-version=1
tags=
short-description=
change-log=
page-url=http://www.d4science.org
author=D4Science Org
licenses=EUPL

If you performed the above procedure correctly now your project should look similar to the picture below:

DeploymentDescriptors.jpg

Download this sample project

You can download this sample project complete with samples for the above files from the link below

File:MyGCubePortlet.tar.gz

The same project is available on the project's svn repository at this URL: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portal/portal-framework/MyGCubePortlet/


  • In your GWT Project html file seek the following part:
<!--                                           -->
    <!-- This script loads your compiled module.   -->
    <!-- If you add any GWT meta tags, they must   -->
    <!-- be added before this line.                -->
    <!--                                           -->
    <script type="text/javascript" language="javascript" src="mygwtproject/mygwtproject.nocache.js"></script>
  • Open your ./war/WEB-INF/jsp/LoginPortlet_view.jsp file and add the content of the <script> element above as shown below
    • Notice that request.getContextPath is added, together with the div using as id the unique name you specified in your entrypoint class
<portlet:defineObjects />
--%>
<script type="text/javascript" language="javascript" src='<%=request.getContextPath()%>/mygwtproject/mygwtproject.nocache.js'></script>
 
<div id="a unique id for the DIV">
</div>

  • The CSS file Location of your GWT application must be set into the <header-portlet-css> element of the liferay-portlet.xml file as shown below (mygwtproject.css is in the war/ folder in this example)
<liferay-portlet-app>
	<portlet>
		<portlet-name>WebLogin</portlet-name>
		<icon>/icon.png</icon>
		<layout-cacheable>false</layout-cacheable>
		<instanceable>false</instanceable>
		<ajaxable>false</ajaxable> 
		<!-- LOCATION CSS HERE -->
                <header-portlet-css>/mygwtproject.css</header-portlet-css>
	</portlet>
	<role-mapper>
		<role-name>administrator</role-name>
		<role-link>Administrator</role-link>
	</role-mapper>
</liferay-portlet-app>

Compile GWT Inside the Portlet Project

You can now compile your GWT Application (Inside the portlet Project) by using the Eclipse Plugin as shown below


GWTCompile.jpg



Set the Portlet Context (How to get the logged in user's information)

In order to get a GCube Portlet work into the portal you need to pass it the context in which the portelt is running into.

To do so: Get the latest version of the module org.gcube.portal.custom-portal-handler from ETICS.

CustomPortalHandler set the portlet context transparently to the developer (no need to call Liferay API as used to do in the past). Instead of asking for the username, it sets that in the session. So that the new doView() method will look like:

public void doView(RenderRequest request, RenderResponse response)    throws PortletException, IOException {
    ScopeHelper.setContext(request); // <-- Static method which sets the username in the session and the scope depending on the context automatically
    PortletRequestDispatcher dispatcher = getPortletContext().getRequestDispatcher(....);
    dispatcher.include(request, response);
}

Moreover, from within the GWT servlets you can get the current username from the http session using the ScopeHelper.USERNAME_ATTRIBUTE e.g.

HTTPSession httpSession = this.getThreadLocalRequest().getSession();
String sessionID = httpSession.getId();
String username =  httpSession.getAttribute(ScopeHelper.USERNAME_ATTRIBUTE).toString();

Migrating from Liferay 6.0 to Liferay 6.2.5

  • DTD
  • Portlet descriptors
  • web.xml - > sevlet 3.0

UsersManagement Library 2.0

VRE, VO e RootVO are modelled as Sites (Not Organisations anymore)

  • Usage of Liferay API Directly is forbidden
  • UserModel -> GCubeUser, e role e group

PortalManger 2.0

    • gateway name & URL
    • mail sender
    • infrastructure name

Invalid language.

You need to specify a language like this: <source lang="html4strict">...</source>

Supported languages for syntax highlighting:

4cs, 6502acme, 6502kickass, 6502tasm, 68000devpac, abap, actionscript, actionscript3, ada, aimms, algol68, apache, applescript, arm, asm, asp, asymptote, autoconf, autohotkey, autoit, avisynth, awk, bascomavr, bash, basic4gl, bf, bibtex, blitzbasic, bnf, boo, c, caddcl, cadlisp, cfdg, cfm, chaiscript, chapel, cil, clojure, cmake, cobol, coffeescript, cpp, csharp, css, cuesheet, d, dart, dcl, dcpu16, dcs, delphi, diff, div, dos, dot, e, ecmascript, eiffel, email, epc, erlang, euphoria, ezt, f1, falcon, fo, fortran, freebasic, freeswitch, fsharp, gambas, gdb, genero, genie, gettext, glsl, gml, gnuplot, go, groovy, gwbasic, haskell, haxe, hicest, hq9plus, html4strict, html5, icon, idl, ini, inno, intercal, io, ispfpanel, j, java, java5, javascript, jcl, jquery, kixtart, klonec, klonecpp, latex, lb, ldif, lisp, llvm, locobasic, logtalk, lolcode, lotusformulas, lotusscript, lscript, lsl2, lua, m68k, magiksf, make, mapbasic, matlab, mirc, mmix, modula2, modula3, mpasm, mxml, mysql, nagios, netrexx, newlisp, nginx, nimrod, nsis, oberon2, objc, objeck, ocaml, octave, oobas, oorexx, oracle11, oracle8, oxygene, oz, parasail, parigp, pascal, pcre, per, perl, perl6, pf, php, pic16, pike, pixelbender, pli, plsql, postgresql, postscript, povray, powerbuilder, powershell, proftpd, progress, prolog, properties, providex, purebasic, pycon, pys60, python, q, qbasic, qml, racket, rails, rbs, rebol, reg, rexx, robots, rpmspec, rsplus, ruby, rust, sas, scala, scheme, scilab, scl, sdlbasic, smalltalk, smarty, spark, sparql, sql, standardml, stonescript, systemverilog, tcl, teraterm, text, thinbasic, tsql, typoscript, unicon, upc, urbi, uscript, vala, vb, vbnet, vbscript, vedit, verilog, vhdl, vim, visualfoxpro, visualprolog, whitespace, whois, winbatch, xbasic, xml, xpp, yaml, z80, zxbasic


int i = 0;

ASL Social 1.0

    • public ApplicationNotificationsManager(HttpServletRequest request, String scope, SocialNetworkingUser currUser)

Troubleshooting

General issues encountered by developers

  • Once you try to compile your Dynamic Web Project GWT2 Powered you get the following exception
[ERROR] Unexpected
java.lang.NoSuchFieldError: reportUnusedDeclaredThrownExceptionIncludeDocCommentReference

Cause:  : Tomcat classpath is listed before your GWT classpath

Solution:  : Go to your Project Properties > Order and Export and make sure GWT SDK is listed before Tomcat one


  • Facet 3.0