|
My First Stripe
As a first application we'll develop a simple, one page calculator that can
take two numbers and perform additions, and maybe some other operations later.
First off, lets get the JSP into shape. The following is a first cut at a JSP.
You'll want to put it in a directory called 'quickstart' off your web
application root.
The JSP
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ taglib prefix="stripes" uri="http://stripes.sourceforge.net/stripes.tld"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head><title>My First Stripe</title></head> <body> <h1>Stripes Calculator</h1>
Hi, I'm the Stripes Calculator. I can only do addition. Maybe, some day, a nice programmer will come along and teach me how to do other things?
<stripes:form action="/examples/quickstart/Calculator.action" focus=""> <table> <tr> <td>Number 1:</td> <td><stripes:text name="numberOne"/></td> </tr> <tr> <td>Number 2:</td> <td><stripes:text name="numberTwo"/></td> </tr> <tr> <td colspan="2"> <stripes:submit name="addition" value="Add"/> </td> </tr> <tr> <td>Result:</td> <td>${actionBean.result}</td> </tr> </table> </stripes:form> </body> </html>
The first interesting thing in the page above is the second line (the one
beginning <%@ taglib .... That imports the Stripes Tag Library for use within the page.
Then, a little lower, the line:
<stripes:form action="/examples/quickstart/Calculator.action" focus="">
opens up a stripes:form tag. The Stripes form tag does a bunch of things we won't go
into here, and ultimately produces a regular html form tag on when the page is
rendered. The focus="" tells Stripes to automatically set focus into the first
visible field (or the first field with errors when there are errors).
Next, we see two tags, something like:
<stripes:text name="numberOne"/>
This is the Stripes equivelant of a <input type="text"/> tag, but provides functionality for
pre-populating, re-populating, and changing display when there are validation
errors. The name numberOne corresponds to the name of a property on the ActionBean
that will receive the request.
Instead of a <input type="submit"> we see:
<stripes:submit name="addition" value="Add"/>
The Stripes submit tag has additional functionality to render localized
Strings on the button, but that's more than we need here, so the tag simply
uses the value attribute. The name of the submit button, addition, is very
important as this is tied to the method that will be invoked on the ActionBean
receiving the request.
Lastly, a small EL expression is used to print the result property of the
ActionBean if it is present.
<td>${actionBean.result}</td>
We're now ready to preview our page! When the page first renders there is no
ActionBean present (one is not instantiated by the form tag, and we
haven't posted this form).
|
Calculator example page after writing the just the
JSP
|
|