Quantcast
Channel: Dr. Chuck's Blog
Viewing all articles
Browse latest Browse all 244

How to build a JSR-168 Portlet in Sakai

0
0

Using JSR-168 portlets is the only way to have a page (like Overview) with multiple tools on the page rendered without iframes.  The portal only removes iframes when a page has one tool.  If there are > 1 tools – it uses iframes.   But JSR-168 tools never use iframes no matter how many there are on the page.

It is pretty easy to convert a servlet-style tool to portlet-style – in particular if the tool uses either JSP or Velocity templates, t is pretty simple.

Here is an example of a tool that uses Velocity:

https://github.com/sakaiproject/sakai/tree/master/web/web-portlet

https://github.com/sakaiproject/sakai/blob/master/web/web-portlet/src/java/org/sakaiproject/portlets/PortletIFrame.java

This was a direct conversion from an old iframe+servlet style tool used in earlier versions of Sakai:

https://github.com/sakaiproject/sakai/tree/master/web/web-tool

If you want to use JSP as your templating language, the following is a sample JSR-168 portlet:

https://github.com/sakaiproject/sakai/tree/master/basiclti/basiclti-portlet

https://github.com/sakaiproject/sakai/blob/master/basiclti/basiclti-portlet/src/java/org/sakaiproject/portlets/IMSBLTIPortlet.java

The portlet model sends GETs go to “view” methods and POSTs to “action” methods.  Our Velocity tools have the same concept of action and view – but they are hand-layered on top of a servlet using convention and classes like VelocityPortletPaneledAction so the pattern will be familiar for those who wander through old Sakai code.

Another interesting bit of Portlets is that they have view “modes” like “Help” and “Edit” that are part of the spec.  Velocity “portlets” have panels but they are not as formally defined.

For example if you see a JSR-168  portlet in Sakai (image)  (Home Information is a portlet) , there is a “Edit” button that comes from the *portal* in the portal title line.  That edit is not part of the portlet’s markup – the portlet simply declares one of its views as “the edit view” and Sakai puts up the button and wires it up.

For an old-school Velocity servlet pretending to be a portlet in an iframe (like Message of the in the image) the “edit mode” is just another panel in the tool and the tool puts out markup with a link to its “edit view” in “Options” below.

It is surprisingly easy to convert from the old to the new because the view/panel and action patterns already are pretty parallel – the velocity servlet that is a fake portlet was one of the inspirations for  JSR-168 so the similarity is not random.  Both were “cool” MVC approaches in 2001-2003.

I love the JSR-168 pattern for multiple independent rectangles on a page.  There is a clever pattern that allows all of the rectangles to handle the back button and refresh in a consistent manner for all three rectangles simultaneously.  I would love it if all the Sakai tools were rewritten as portlets – but with the magic iframe inlining since Sakai 11 – it is only really beneficial for synoptic tools.


Viewing all articles
Browse latest Browse all 244

Latest Images

Trending Articles





Latest Images