Software Reality
Programming with
a dose of satire.

Site Map Search


Agile Development
 
Extreme Programming
 
Code Generation


Articles
Lifecycle
Design
Programming
Soapbox
Reviews
Cthulhu

Check out our ageing Reviews Section


Use Case Driven
Use Case Driven Object Modeling with UML: Theory and Practice
Get from use cases to working, maintainable source code. Examples use Spring Framework, JUnit and Enterprise Architect

Agile UML
Agile Development with ICONIX Process
A practical subset of agile development techniques, illustrated by example

Get Controversial!
Extreme Programming Refactored
Extreme Programming with a dose of satire
Available now:



ICONIX/Sparx Public Classes to Come to London

ICONIX is planning a series of open- enrollment public classes entitled Hands-On Enterprise Architect for Power Users in collaboration with Sparx Systems.




Slots Web Framework

Slots User Guide

<< Slots Central

 

What is Slots?

Slots is a templating framework for servlets and JSP. However, 'framework' isn't entirely accurate, unless you consider 2 class files a framework.

Yes, that's right, the entirety of Slots is 2 class files, the main controller servlet SlotServlet, and an extremely useful wrapper class that calls a page and returns its response in a string, SlotWrapper. The only other file needed is slots-config.properties, which defines your templates and page definitions.

Slots was created in order to give developers an easy to understand, easy to learn templating framework, where you don't have to buy several books, get a mortgage on a second brain, nor swear alegiance to a new coding religion. All the code is open source, and given the size of the code base (around 350 lines), only takes a few minutes to get your head around. I assume you understand basic Servlets and JSP, nothing else is needed. There is no concept of deploy, no need to stop/start the JSP engine, simply alter your JSPs or slots-config files, then refresh your browser. This leads to very rapid iterations, no 60 second deploys.

 


User Guide

Here is an example of a very simple slots-config:

default=mybase
mybase=base=/pagetemplate.jsp

That's all you need to start using slots. What we are saying here is that for any file we give to Slots, we will use pagetemplate.jsp as its template definition.

pagetemplate.jsp can be as simple as:

<html>
<body>
SOME HEADER<BR>
<%=request.getAttribute("slots_content")%>
<BR>SOME FOOTER
</body>
</html>

If I call /slot/test1.jsp it will invoke test1.jsp and insert its response into the request attribute slots_content, then invoke pagetemplate.jsp

In doing this, every page so invoked can be guaranteed to have the same layout and structure. Should I wish to change this global layout, all I have to do is alter pagetemplate.jsp

Now I'd imagine that this simple template would not be enough for your needs. For example you may wish to have configurable page titles.

In this case we might have pagetemplate become

<html><head>
<title><%=request.getAttribute("slots_title")%></title>
</head>
<body>
SOME HEADER<BR>
<%=request.getAttribute("slots_content")%>
<BR>SOME FOOTER
</body>
</html>

Then change slots-config to say:

default=mybase
mybase=base=/pagetemplate.jsp,title="My Site:"

Then every page would have "My Site:" as a title. However how would we specify per page titles? Easy, just say:

/test1.jsp=title="Test 1 page"

We use the default template, as before, buit this time override the title slot for this page. We aren't limited to static strings and could easily say:

/test1.jsp=title=/title.jsp

in order to delegate the page title to another jsp. I can even say

/admin=title="Admin"

to have all files under /admin automatically take a custom value for title.

Should I wish to have more than one tempate, not uncommon, its as easy as

adminbase=base=/admintemplate.jsp,title="Admin"
/admin=base=adminbase

i.e. all pages under /admin get to use this admintemplate, and get a default title of "Admin".

I can even define a base as inheriting from another base e.g.

managerbase=base=adminbase,title="Manager"
/admin/manager=base=managerbase

A common need in web based applications is to rename pages or otherwise refactor how things are handled in your workflow. In Slots this is easy:

/test1.jsp=content=/someotherfile.jsp

By overriding the content slot I actually delegate page content to another page altogether. I can even supply mocked up contents for a page I have yet to fully define, e.g.

/test1.jsp=content="TODO: test 1"

For every slot you have in an entry, you get a "slot_slotname" entry in the request attributes with the value of that slot, either static string, or the response from another page.

e.g. if I say

/test2.jsp=title="Test 2 page",otherslot=/somethingelse.jsp

then when I call /slot/test2.jsp it will insert slot_title with "Test 2 page" and slot_otherslot with the response from /somethingelse.jsp. These will override any similarly named slots from the default base, if any.

test2.jsp will then be called, with all these values in the request attributes, to use or ignore as it sees fit. This response will then be inserted into slots_content, which then gets passed onto the default base jsp page, once again to use or ignore as it sees fit.

 

<< Slots Central

<< Software Reality Front Page

 

All trademarks and copyrights on this page are owned by their respective owners.
Stories and articles are owned by the original author.
All the rest Copyright © 1998-2007 Matt Stephens. ALL RIGHTS RESERVED.