Wednesday, 4 July 2007

SimpleFormController Cheat Sheet

I felt I didn't have a good understanding of Spring MVC until I understood the lifecycle of the controller. Not being able to find any good resources that showed the workflow step by step, I created this flowchart of the SimpleFormController.

In a single page cheat sheet format, I've found it handy to keep it on my desk. For the beginner, it should be used in conjunction with the API, and nothing beats firing up a debugger and stepping through the code yourself. Once you understand the SimpleFormController, you can easily understand the WizardFormController or create your own custom controller.

I hope someone will find this useful. Please leave comments and let me know if anything is wrong, or if there are any suggestions. Cheers!

SimpleFormController Cheat Sheet

Tuesday, 3 July 2007

Fluid Horizontal Menu - Using UL, CSS (and a table)

In the A List Apart article: Taming Lists there is a very simple example of using UL to markup a horizontal list. Making this into a fluid full width menu proved much more difficult than I thought, and I have provided the implementation here.

The broad requirements of this are:

  • There is a color for the menu, and another color for the current item. The menu has a bottom border the same color as the current item.
  • The menu must not wrap when browser is resized, it must always be a single horizontal row
  • When browser width is smaller than menu, scrolling the viewport across will still display the menu bottom border
  • When browser width is larger than the menu, the menu expands to 100% width
  • The items in the menu are dynamically generated on the server (so the number of items may vary, as can the total possible width)
Show below, is the screenshot of the final product.

The final code to produce this menu is as follows:

<style type="text/css">
li, ul {
   padding: 0;
} {
   background-color: #CCC;
   border-bottom: 5px solid #8C78C5;
   width: 100%;
   padding: 0;
} td, tr {
   border: 0; padding: 0;
} ul {
   white-space: nowrap;
   padding: 4px 0px;
} li{
   display: inline;
   list-style: none;
} a{
   background-color: #CCC;
   padding: 4px 10px;
   color: black;
   text-decoration: none;
   border-left: 1px solid white;
} a:hover {
   text-decoration: underline;
} a.first {
   border-left: none;
} a.current{
   color: white;
   background-color: #8C78C5;

<!--[if IE]>
<style type="text/css"> ul{

<table class="menu"><tr><td><!--
  --><li><a href="#" class="first">Spring MVC framework</a></li><!--
  --><li><a href="#">Struts MVC</a></li><!--
  --><li><a href="#" class="current">Tapestry</a></li><!--
  --><li><a href="#">JSF</a></li><!--
  --><li><a href="#">Java Server Pages</a></li><!--

To summarise the main points of the implementation:

  • The LI are inline, and the UL has white-space:nowrap so that the items are in a single row
  • The background-color is defined in the anchor so that the entire "tab" is clickable
  • To increase the height of each "tab", add padding to the anchor, and also to the UL because the anchors are inline elements
  • We need the container to expand to accomodate its content regardless of browser viewport size, so that the bottom border stretches with the content. A table is used because IE doesn't suppport display:table* attributes
  • Whitespace is commented out because for some reason compliant browsers render a gap
  • An IE only rule is provided to solve a problem which appears to be collapsing related.

For the full explaination of this menu, see my article Fluid Horizontal Menu - Using Unordered List, XHTML, CSS (and a table)

This menu has been tested on IE6, IE7, Firefox 2, Opera 9, and Safari 3beta