Mentawai Web Framework

HTML Tags

Mentawai comes with some html tags that can save you a lot of boring work. Consider the html form below:

<form action="Register.mtw" method="post">
Name: <input type="text" name="fullname" size="50" maxlength="60" /><br/>
Username: <input type="text" name="username" size="20" maxlength="30" /><br/>
Password: <input type="password" name="pass" size="20" maxlength="20" /><br/>
Confirm: <input type="password" name="conf" size="20" maxlength="20" /><br/>
Zip: <input type="text" name="zip" size="20" maxlength="20" /><br/>
Accept term: <input type="checkbox" name="accept" value="1" /><br/>
<input type="submit" value="Send Now!" />
</form>
                

When the user submits this form, it will go through validation and if an error is found the page is displayed again to the user. Of course you don't want your user to type everything back again because his zipcode was wrong, so the question is: How do you keep the valid form data from disappearing? With Mentawai tags, all you have to do is this:

<%@ taglib uri="/WEB-INF/lib/mentawai.jar" prefix="mtw" %>
<form action="Register.mtw" method="post">
Name: <mtw:input type="text" name="fullname" size="50" maxlength="60" /><br/>
Username: <mtw:input type="text" name="username" size="20" maxlength="30" /><br/>
Password: <mtw:input type="password" name="pass" size="20" maxlength="20" /><br/>
Confirm: <mtw:input type="password" name="conf" size="20" maxlength="20" /><br/>
Zip: <mtw:input type="text" name="zip" size="20" maxlength="20" /><br/>
Accept term: <mtw:input type="checkbox" name="accept" value="1" /><br/>
<input type="submit" value="Send Now!" />
</form>
                

The Mentawai input tag, as all other Mentawai html tags, looks for the data in the underlying action. The rule is:

You don't even have to know that. You form is not losing the user information anymore and you did not have to write a single line of code to accomplish that!


Integration with Data Lists

Mentawai html tags are integrated with data lists (if you don't know what a data list is, you can learn here) so that you can easily display a form list. Let's suppose, for example, that you have a genders data list. Check the code below:

<%@ taglib uri="/WEB-INF/lib/mentawai.jar" prefix="mtw" %>
<form action="Register.mtw" method="post">
Name: <mtw:input type="text" name="fullname" size="50" maxlength="60" /><br/>
Username: <mtw:input type="text" name="username" size="20" maxlength="30" /><br/>
Password: <mtw:input type="password" name="pass" size="20" maxlength="20" /><br/>
Confirm: <mtw:input type="password" name="conf" size="20" maxlength="20" /><br/>
Zip: <mtw:input type="text" name="zip" size="20" maxlength="20" /><br/>
Gender: <mtw:select name="gender" list="genders" /><br/>
Accept term: <mtw:input type="checkbox" name="accept" value="1" /><br/>
<input type="submit" value="Send Now!" />
</form>
                

The mentawai select tag creates a html select tag with the items from the genders list.

You can also create checkboxes and radio buttons with the list items:

<!-- This does not make sense -->
Gender: <mtw:checkboxes name="gender" list="genders" /><br/>

<!-- This is better! -->
Gender: <mtw:radiobuttons name="gender" list="genders" /><br/>
            

Remember that these tags have the same functionality of the input tag, in other words, they don't lose the form data!


More Control

The Mentawai input, select, checkboxes and radiobuttons tags have more attributes that you can use to better control their behaviour.

For example, the select has the emptyField attribute that when set to true will include a empty item in the list, like this:

<option value="0"> - </option>
            

You can also create more HTML tags by inheriting from the org.mentawai.tag.html.HTMLTag or you can override the existing Mentawai tags to fine-tune their behaviour.

For more information on these tags, please refer to the API documentation.