ONJava.com -- The Independent Source for Enterprise Java
oreilly.comSafari Books Online.Conferences.

advertisement

AddThis Social Bookmark Button

Improve Your Career with Tomcat and Aspire
Pages: 1, 2

Aspire's Simplified Tags

The goal here is not to be detailed but to give you an understanding of the complexity (really, the simplicity) involved. In this case, the merging is accomplished through a replacement tag pair that looks like {{ and }}.



Here is an example:

Hello my first name is {{arg1}} and my last name is {{arg2}}

Aspire will replace arg1 and arg2 from the maindata data set. Here is how you can use the data from the list1-data set.

<!RLF_TAG BGN_LOOP list1-data -->
Any repeatable html section such as {{col1}} and {{col2}} and if needed {{arg1}}
<!RLF_TAG BGN_LOOP list1-data -->

The same thing goes for table1-data and table2-data. The tags are designed with two important goals. The first is to preserve the design of the page with the tags present. That is, the tags should not impede the ability of the designer to see the page in the design tool with minimal impact. For this reason, the tags are embedded either in comments or directly exposed to the designer. The second goal is to allow the designer to directly identify the dynamic elements while in the design tool itself. In the case above, {{arg1}} can be directly typed in FrontPage with out switching back to the HTML view. To allow for conditional inclusion of a page based on a certain matching criteria, there is a programmable IF tag available as well.

Merging with JSP

When the page is too difficult to handle with the simple tags documented above, you can use JSP instead. Here is an example of using JSP for merging data and the screen:

<%
        //Get the data object
        IFormHandler pageData = request.getAttribute("Aspire.Dataset");
%>

Hello my first name is <%=pageData.getValue("arg1") %> 
and my last name <%=pageData.getValue("arg2")%>

At the top of your HTML page (or JSP page) you receive the object into a local variable called pageData. This object and the available methods on that object are used to retrieve data and place on the page. Basic JSP is very simple to teach -- it takes perhaps less than an hour. JSPs can get complicated, but the goal of the tool is to make this process trivial and easy.

See how the values for arg1 and arg2 are retrieved from pageData and substituted onto the HTML page just like the {{arg1}} in the tags scenario.

The next example of JSP shows how one can populate repetitive structures, such as list boxes and tables. Data for each repetitive structure is also available in pageData, albeit with a name identifying it. This is necessary because on a given page, you may have more than one repetitive structure. Each structure is identified by a name. Once you know the name, you can access the data for the repetitive structure using its name.

Here is how you can use the data from list1-data set:

<%
     IControlHandler list1Data = pageData.getControlHandler("list1-data");
     while (list1Data.gotoNext())  {
%>
     Any repeatable html section such as <%=list1Data.getValue("col1") %> 
     and <%=list1Data.getValue("col2") %>  
     and if needed <%=list1Data.getValue("arg1")%>
<%   }%>

The data for list1-data is retrieved from pageData into a variable called list1Data and, using a simple while loop, all of the rows are traversed. See the similarities of list1Data.getValue() and pageData.getValue(). In essence, the number of APIs that the developer needs to know is very minimal. It is this simplicity that makes the JSP merging easy and powerful.

Merging with XSLT

For the sake of brevity, I will not go into the details of the XSLT, but it is very similar to the JSP section, except that you are using XPATH expressions for substitute and loop through. The example of this can be seen at the Aspire demo site.

JSP and XSLT: Are They not Complex Enough for the Stated Simplicity?

In the cases of both JSP and XSLT we are using a very minimal set of their respective facilities; in both cases we are limiting ourselves to the control flow statements of a language. You are basically using assignment, if/else, and loops. These should be very familiar to the relational developers, as they use these structures in writing stored procedures.

How do Updates Work?

Performing updates based on HTML forms is quite intuitive and flexible using Aspire. Let us consider a URL that is coming from the browser as a result of form posting:

http://www.examplecompany.com/webapp1/AspireUpdateServlet
    ?request_name=update-employee
    &arg1=50

    &arg2=60

The above invocation implies that you want to call a business logic called update-employee with two arguments arg1 and arg2. How can you facilitate this so that your stored procedure, mypkg.sp_update_employee arg1, arg2, is called? Here is the configuration to do this (we've had to add some line breaks for formatting purposes here):

Request.update-employee.classname=com.aspire.StoredProcedure
Request.update-employee.db=mydatabase
Request.update-employee.stmt=call mypkg.sp_update_employee {arg1}, {arg2}
Request.update-employee.type=update

Request.update-employee.redirecturl=
/webapp/AspireDisplayServlet?url=someotherpage-or-thesamepage&arg3
={arg3-value}

Request.update-employee.failure-redirecturl=
/webapp/AspireDisplayServlet?url=someotherpage-or-thesamepage&arg3
={arg3-value}&error=true

Request.update-employee.failure-redirecturl.errorcode.EMPLOYEE-DOESNT-EXIST=
/webapp/AspireDisplayServlet?url=someotherpage-or-thesamepage&arg3=
{arg3-value}&error=true

Aspire will pass the arguments to your proc and if the proc doesn't throw any exceptions, the user is redirected to the URL identified by redirectURL; if the exception has an error code, EMPLOYEE-DOESN'T-EXIST, the user gets redirected to that URL. If the error code doesn't match, the user is redirected to general failure-redirect-url.

How Long for a Typical Relational Developer to Start Effectively Exploiting the Web to Enhance His or Her Career?

Here is a toolset that can seamlessly transform your relational developers to Web developers in about a week. The toolset is firmly rooted in architecture and J2EE and provides a gradual learning path for the development teams into the complex areas of J2EE, while providing simple solutions to simple problems. Being a no-cost alternative should be attractive as well.

This could also work as a career-enhancement proposition to the database developers, as they can directly impact the business processes utilizing their superior knowledge of corporate data. The goal is to make the relational developers take on the role of architects in enterprises and thereby provide a well-rounded career path.

Additional Help

For individuals that are interested in this article and want to try out the tools outlined, or corporations that want to further explore the deployment opportunities available for open source J2EE architectures like the ones proposed here, email me at satya@activeintellect.com.

Additional References

Satya Komatineni is the CTO at Indent, Inc. and the author of Aspire, an open source web development RAD tool for J2EE/XML.


Read more {name} columns.

Return to the ONJava.com.