Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Rapid Template-Driven Development with Jakarta Velocity : Page 3

Increase your efficiency and lower your stress in developing Web applications by using templates.


advertisement
Approach 2. Embedding Smart Code in the HTML
This is the approach used by technologies such as PHP, ASP, or JSP, where you embed tags in the HTML document that the server interprets and executes, changing or generating HTML for you on the fly. For the purposes of this example I'll use PHP, but the approach using ASP or JSP is similar.

<table border="1" width="100%" id="table1" class="ms-classic4-main"> <!-- fpstyle: 7,011111100 --> <tr> <td class="ms-classic4-tl">Name</td> <td class="ms-classic4-top"> <p align="center">Company</td> <td class="ms-classic4-top"> <p align="center">Sales details</td> <td class="ms-classic4-top" align="right"> <p align="center">Amount</td> </tr> <? $result= mysql_query($strSql) or die(mysql_error()); if($result) { while ($row = mysql_fetch_array($result)) { ?> <tr> <td class="ms-classic4-left"><?php echo($row['personname']);?></td> <td class="ms-classic4-even"><?php echo($row['customername']);?></td> <td class="ms-classic4-even"><?php echo($row['contractdescription']); ?></td> <td class="ms-classic4-even" align="right"> <?php echo($row['amount']);?></td></tr> <? } } ?> </table>

As you can see, the preceding code closely resembles the original HTML file, except that the hard-coded values have been removed in favor of code that generates the values from the database.

Figure 3. PHP Report Output: Here's the report output generated by the PHP example.
Figure 3 shows the output generated from the PHP page. Pretty good, huh?

The problem here is similar to that with the previous approach. You had to take the HTML off the designer, and amend it to "activate" it. This approach is less intrusive, as the developer needs only to add to the existing mockup HTML, rather than taking all the code and line-by-line putting it into out.println statements as in the servlet example—but the problem is, what happens when the HTML changes? You get an all-new document without your PHP tags in it, and have to start again. There are workarounds, such as making the designer work with your PHP when tweaking their design, but from experience this has led to more problems that it has solutions as WYSIWIG designer tools such as FrontPage can end up overwriting your code.



Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap