Tutorial - Objective Html Compiler
Author Keith Wong, keithwong@optushome.com.au
Last updated: 19th Jan 2002
Example Code
These are the files for this example.
customer.html [source code]
customer.jsp [source code]
CustomerForm.java [source code]
CustomerFormDesign.java [source code]
PostCode.java [source code]
The binaries can be downloaded below (packaged in a war file). In Tomcat, simple place the war file under
the "webapps" directory, it will automatically explode when Tomcat is started up.
Make sure the objectivehtml-java-alphaX.jar is in the Tomcat $TOMCAT_HOME/lib directory.
You should then be able to view the
form using the URL http://localhost:8080/objectivehtml-ohtmlc/customer.jsp. Replace the server address
and port number if your computer is setup differently.
objectivehtml-ohtmlc.war
Introduction
This tutorial continues on from the signals and slots tutorial. If you have not gone through that tutorial then it is suggested you go back and read that one before proceeding.
In this tutorial we'll give you a brief guide into how you can use the Objective Html Compiler (ohtmlc). The ohtmlc tool will compile static html forms into OHtml forms providing you with a great facility to separate your form design from your form logic.
Once again we have our customer details form. The requirements haven't changed, the only thing we will change is our approach to implementing the CustomerFormDesign class. Instead of writing this class manually we will design the customer form in static html and use ohtmlc to construct the the code for the CustomerFormDesign class.
Code Walk-Through
customer.html
Try opening this file in a browser or a WYSIWYG html editor. You should be able to see there is nothing special about this file, it is just a normal html file that has the basic customer form design.
Now before we generate the CustomerFormDesign class we need to do a few things to the file first. The ohtmlc uses a JAXP 1.x compatible compiler, which means that your html file must at least be a well formed xml document. Now most WYSIWYG html editors don't usually generate well formed xml documents, however we do have a solution for this problem and thats HtmlTidy. HtmlTidy is an excellent tool that can basically fix up almost any badly formed html document. The command we used to fix up this document was:
htmltidy --output-xml y customer_orig.html > customer.html
This command will generate a well formed xml document and the good thing about this is that the file should be still viewable by most browsers. The file generated will also have all tag names and attribute names in lower case which is another requirement of ohtmlc.
CustomerFormDesign.java
We are now ready to generate the CustomerFormDesign class. The command we ran was:
ohtmlc -package mypackage -exceptions Exception customer.html CustomerFormDesign
The -package option simply indicates the package the class is in and the -exceptions option indicates the exceptions to be thrown by the constructor. The last two arguments are the input html file and the class name of the class to be generated. This command will produce a file with the same name as the class name, i.e. CustomerFormDesign.java.
Something to note is that we generated a number of member variables in our CustomerFormDesign.java file. The ohtmlc will generate a member variable whenever it encounters either an element with an id attribute or a form element. The member variable name is the same as the name given in the id attribute or name attribute (only for form elements).
Conclusion
And thats its all the other classes in this tutorial as the same as the previous one. The ohtmlc tool gives you a clean and easy way to separate our form design from your form logic. It also provides developers with an easier way to build your OHtml forms. If anyone picks up mistakes in this tutorial please let me know.