OOP-ResearchMake It Simpler by Object Oriented Programming

OOP ViewGenerator API : Simpler than JSP, JSTL, Apache Struts or JavaServer Faces / Input validation from CGI FORM / Easy localization (L10n) / Servlet in Japanese Shift_JIS, Chinese BIG5 or GB2312

Servlet by XML. Simpler than JSP/JSTL, Apache Struts or JavaServer Faces. Input validation from CGI FORM. Localization (L10n). Servlet in Japanese Shift_JIS, Chinese BIG5 or GB2312.
In the framework design by OOP ViewGenerator API, all the Servlet response can be written in the normal HTML or any other mark-up languages (such as XHTML, WML or HDML). Unlike the JSP/JSTL based solution such as Apache Struts or JavaServer Faces, the web designers (or page authors) need not learn a bit of the custom tag libraries.
And the localization (L10n) is much easier with this Java API. In case of Apache Struts or JavaServer Faces, the localized messages should be written in the property resource file for the expected Locale. But, in this framework, the normal HTML with the localized messages will be enough. There is not difficulty even in the 2 bytes characters such as Japanese Shift_JIS, Chinese BIG5 or GB2312.
The conversion tool with its easy to use Java Swing GUI takes care of the conversion to XML from HTML. This conversion tool asks you to specify the acceptable data type for each request parameter from the CGI FORM.

Putting it all togather : OOP Bento framework

This Java API is now a part of OOP Bento framework. In this MVC framework by XML, you can write all the GUIs in the web application in the normal HTML, XHTML, WML, HDML or any other mark-up languages. And you no longer need to bother about the user authentication and the session tracking. Because its full working source code example will be the good starting point of this Java API, please also try OOP Bento framework.

Related Pages:


Servlet response by the normal HTML!

Believe or not, all the response from your Servlet can be written in just the normal HTML (or any mark-up languages such XHTML, WML or HDML)! Unlike the JSP/JSTL based solutions like Apache Struts or JavaServer Faces, the web designers (or page authors) of your project need not know even a bit of the custom tag libraries. Once the response is written in the normal HTML, it's time to run HtmlToXml conversion tool:

HtmlToXml
[HtmlToXml]

This Java Swing GUI based conversion tool converts the normal HTML into the template XML. You can also update the template XML by HtmlToXmlEdit, another GUI tool in this Java API.

HtmlToXmlEdit
[HtmlToXmlEdit]

Both of these tools are included in OOP ViewGenerator API. When you finish the template XML, please place them into:
  • (docBase)/WEB-INF/classes
or its sub-directories. OOP ViewGenerator API reads the template XML, insert the arbitrary Strings between the fragments of tags in the template XML, and send the concatenated tags back to the web browser. By this way, your Servlet can generate the dynamic response from the template XML, that is converted from the normal HTML (or any mark-up languages such XHTML, WML or HDML).
Makes your life easier by OOP ViewGenerator API!
Go Site Map

Input validation from CGI FORM by XML

While interacting with the user, each text field in your CGI FORM expects the specific pattern of input. For example, the user should type only the digit (0-9) in some text field of your CGI FORM. If s/he sends the wrong input, the destination Servlet should detect it and show the same CGI FORM again. But the CGI FORM at this time should include all the previous inputs in it as the default value. In addition, the wrong input should be highlighted by the colored font or something:

CGI FORM with invalid input
[CGI FORM with invalid input]

By the help of OOP ViewGenerator API, a few lines of code are enough for the input validation in your Servlet.
When you work with HtmlToXml, you can specify the acceptable data type for each request parameter from the CGI FORM:

Acceptable data type for request parameter
[Acceptable data type for request parameter]

Along with the set of the HTML tags, these information are also written into the template XML. Given these information from the XML, your Servlet can check all the request parameters at once.
For instance, the source code of your ServletWorker will look like this:


public class CheckOnly implements ServletWorker{

    private static RequestParser reqParser;
    private static ViewGenerator viewGenerator;

    public CheckOnly()
        throws Exception{
        reqParser=RequestParser.getInstance();
        viewGenerator=ViewGenerator.getInstance();
    }

    public void work(HttpServletRequest req, HttpServletResponse res)
        throws NestedException,SimpleException{
        try{
            // Parse the HTTP request ...
            ParsedRequestParameters params=reqParser.parseSimple(req);

            // Verify all the request parameters by just a single line !
            // The second parameter of this method specifies the XML,
            // that is used to verify the request parameters.
            VerifyResult result=viewGenerator.verify(params,0);

            // Insert the values between the tags.
            Map values=new HashMap();
            values.put("date",(new Date()).toString());

           if(result.isAllOk()){
                // If all the request parameters are valid ...
                // The second parameter of this method specifies the XML,
                // that is used to generate the response.
                viewGenerator.writeResponseWithDefault(params,1,res,null,
                                                            values,true);
            }
            else{
                // If any of the request parameters are invalid ...
                // The second parameter of this method specifies the XML.
                // that is used to generate the response.
                // The 4th parameter of this method includes the request
                //  parameters, and they will be appear within the CGI FORM
                // as the default values.
                viewGenerator.writeResponseWithDefault(params,0,res,
                                 result.getResultMap(),values,true);
            }
        }
        catch(NestedException ex){
            throw ex;
        }
        catch(SimpleException ex){
            throw ex;
        }
        catch(Exception ex){
            throw (new NestedException(ex));
        }
    }

} //End of : CheckOnly


Note that the source code above does not bother about the validity of each request parameter from CGI FORM. Based on the information in the XML, OOP ViewGenerator API checks the validities of all the request parameters.
OOP ViewGenerator API works with: and the source code above implements ServletWorker interface.
Go Site Map

Easy localization (L10n)

In case of the JSP/JSTL based solutions like Apache Struts or JavaServer Faces, the localized messages should be written in the property resource file for each Locale. In the template solution by OOP ViewGenerator API, the localization (L10n) of your Servlet is much easier. Please prepare the normal HTML in as many human languages as you like (each of them will includes the localized message for the expected Locale). Because all the localized messages can written in the normal HTML, there is no difficulty even in the 2 byte characters such as Japanese Shift_JIS, Chinese BIG5 or GB2312.

Once you prepare the set of the HTML, please run HtmlToXml conversion tool on the HTML for each Locale and place them into the different path. For example, you may have a set of template XML like below:

  • (docBase)/WEB-INF/classes/xml/en/hello.xml
  • (docBase)/WEB-INF/classes/xml/fr/hello.xml
  • (docBase)/WEB-INF/classes/xml/de/hello.xml
And the deployment descriptor of OOP ViewGenerator API associates the path information of the HTTP request with these XML.
Go Site Map

Download

This API is now a part of Bento framework. There are the better documentations and source code examples on the web site for Bento framework. There, you will also find the link to download the entire framework or each API in it.

Caution!
All the APIs for Servlet/JSP introduced by this web site are now included in Bento framework:
  • Simpler than JSTL or Apache Struts
  • MVC framework by HTML
  • Input validation from CGI FORM
  • Easy user authentication
  • Easy localization (L10n)
To download the APIs and source code examples, please visit the web site of Bento framework.


JBuilder 2007


General Information

For Java Development

Java and all Java-based trademarks and logos are trademarks or registered of Sun Microsystems, Inc. in the United States and other countries.


ALL CONTENTS COPYRIGHT 1997-2007, OOP-Research Corporation. All rights reserved.