|
sketching a jsp page for a chessboard
|
Tom Ritchford
|
May 26, 2001 15:20 PDT
|
enough chat, let's start sketching out how to display
a chess board as a JSP page.
we're JUST going to display a board, not a move history
or a list of pieces captured.
one piece at a time!
[NB:
I'm going to use an iterator
from http://jakarta.apache.org/taglibs/utility
take a look at
<http://jakarta.apache.org/builds/jakarta-taglibs/nightly/src/>
if you want to see where this is coming from -- it's very useful
and shows you how to make your OWN custom tags.
]
<%@ taglib uri="http://jakarta.apache.org/taglibs/utility" prefix="util" %>
<%@ taglib uri="http://editEverything.com/taglibs/ee" prefix="ee" %>
<%@ taglib uri="http://solveChess.com/taglibs/chess" prefix="chess" %>
<ee:parameter id="positionName" name="name"/>
<!--
assume we get a URL like <http://solveChess.com/...?name=0/1/18/4
(or whatever naming we choose)
then this is equivalent to:
String positionName = request.getParameter( request, "name" );
-->
<chess:position id="position" name="positionName"/>
<!--
this is equivalent to:
ChessBoard position = ChessBoard.findPosition( positionName );
-->
<!-- now we make a format-independent table. -->
<ee:table>
<util:For iterations="8" varName="row">
<ee:row>
<util:For iterations="8" varName="column">
<ee:entry>
<chess:represent>
<!-- at this point, we have a position name, a row and a column -->
<!-- so we can just get the piece! -->
<%= position.getPiece( row, column ) %> <!-- simple! -->
</chess:represent>
<!--
the <chess:represent> tag represents a piece as
either text, HTML styled text or a graphic
depending on context.
-->
</ee:entry>
</util:For>
</ee:row>
</util:For>
</ee:table>
<util:For> is Jakarta, and obvious in its functionality.
but what are all these ee and chess tags I'm making up out of
whole cloth?
THE ee TAGLIB
<ee:table>, <ee:row>, <ee:entry>
are format-independent ways of doing what
would be a table in HTML.
these evaluate differently depending on what sort
of protocol we are generating.
so <ee:row>foo</ee:row> would evaluate to:
<tr>foo</tr> for HTML
foo with a carriage return, for command line apps
? who knows? for other formats.
<chess:represent>? why does it know about HTML??
This tag IS needed, though I might need to clarify
it a few times.
There needs to be some part that
a) is part of the chess package
b) knows which square is
c) knows how to display it in SOME different formats
but this tag only needs to have a FEW primitive formats in a
descending(?) order... graphical -> HTML -> text
the ee: tags handle all the multiplicity of formats
beyond that!
/t
...electronic a cappella madness <http://volectrix.com>.........
...extreme internet radio <http://extremeNY.com/radio>...
|
|
 |
|