Hi All,

So anyway, I had this idea.

Recently I am doing a lot of work with html templates (using the
Velocity Templating language).

Anyway, the thing is that I have lots of lots of web management screens
of one sort or another. Each screen is backed by a template, and some
associated code. I have a ControllerServlet passing off requests to
particular templates and processing the associated code.

I do some of this in Turbine (which handles a lot of things
automatically), and some of it not. Either way the paradigm is the same.

Recently I have acquired two habits that I believe are helping me
produce working, effective management screens.

1. I define all HTML form variables in the code associated with the template
2. I use HttpUnit to check that the forms work properly

These two things are related. The function of the first is so that when
I am checking a parameter from a submitted form, I know that I am
checking for precisely the parameter specified in the form, e.g.

**Template segment**

<form name="$EDIT_FORM" action="$FORM_ACTION" method="POST">
<input type="hidden" name="$ACTION" value="$ACTION_TYPE">

**Template generation Code segment**

public class AddBookmarkCommand
{

public static final String ACTION = "action";
public static final String EDIT_FORM = "edit_form";
public static final String FORM_ACTION = "/neurogrid/servlet/forum";
public static final String ACTION_TYPE = "add_bookmark";

public void generateTemplate(VelocityContext p_context)
{
p_context.put("ACTION",ACTION);
p_context.put("EDIT_FORM",EDIT_FORM);
p_context.put("FORM_ACTION",FORM_ACTION);
p_context.put("ACTION_TYPE",ACTION_TYPE);

**Form handling code segment**

public class AddBookmarkCommand
{

String x_action = request.getParameter(ACTION);
if(x_action.equals(ACTION_TYPE))
{
// do some stuff

Anyway, I'm not sure how clear the above example is, and it probably
helps if you know Velocity, but the point is that when I am checking for
attribute/value pairs coming in from html form submissions I know the
form has been supplied with precisely those values.

The HttpUnit code goes something like this:

WebResponse x_jdoc = o_wc.getCurrentPage();
WebForm x_form = x_jdoc.getFormWithName(AddBookmarkCommand.EDIT_FORM);

So perhaps you can see the relation. I am also able to access the static
final HTML form attributes in the test code to ensure that there is no
confusion. Everything that is going to interact with these
attribute/value pairs is refering to precisely the same things.

So one thing I am interested in is getting some feedback on the above
approach.

The other thing is that I am thinking about taking all this a step
further. It would seem possible to write some code that would take an
html template and automatically generate java code that would serve as
the form handling code as well as the testing code. So you write your
template, and then press a button, and hey presto you have a form
handling class that will specify all the necessary final static
variables, and testing code that will check if they are present when you
view the template.

There is a system that sort of does this called Canoo WebTest which I
have been looking at, where you can specify test cases in the form of
XML. However I don't see anyway to link the attribute/value pairs
throughout, in the way I describe above.

Alot of my work involves writing and testing web management screens and
it would be great to be able to streamline the process.

However maybe I am overlooking some serious flaws in my appoach? Any
comments?

CHEERS> SAM




--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>


Reply via email to