Saturday, July 18, 2009

JSP Text Custom Tag

Which is the more proper (i.e. acceptable to Sun, now Oracle's new division)
  • JSP Text Custom Tag, or
  • Text JSP Custom Tag?
The source is at
http://code.google.com/p/synthfuljava/source/browse/#svn/trunk/jsp/org/synthful/jsp/tags/Text.

The TLD is at
http://code.google.com/p/synthfuljava/source/browse/#svn/trunk/jsp/org/resources/WEB-INF.

Anyway, this is a custom tag I wrote because during ancient times I programmed in Perl and when I moved to Java I had to do this Java

String query =
"SELECT NAME, ADDRESS, JOBID " +
"FROM EMPLOYEE E, JOBS J " +
"WHERE E.EID = J.EID AND" +
"E.STATE = '" + state + "' AND " +
"current_date - E.STARTDATE > " + minexp;


instead of, which Perl allows me,

query =
SELECT NAME, ADDRESS, JOBID
FROM EMPLOYEE E, JOBS J
WHERE E.EID = J.EID AND
E.STATE = \'$state\' AND
current_date - E.STARTDATE > $minexp
;



With the Text JSP Custom Tag, I have been doing this

<h2g2j:text id="query" scope="session">
SELECT NAME, ADDRESS, JOBID
FROM EMPLOYEE E, JOBS J
WHERE E.EID = J.EID AND
E.STATE = '<%=state%>' AND
current_date - E.STARTDATE > <%=minExp%>
</h2g2j:text>

  • The contents of the body of the tag is stored in a StringBuffer.
  • The ID="query" attribute associates the StringBuffer to Java variable "query".
  • Specifying the ID attribute clears the StringBuffer before storing the tag's contents into the StringBuffer.
  • Instead of using the ID attribute, the REF attribute should be used to invoke the tag identified by "query" without clearing the StringBuffer.

<h2g2j:text ref="query" scope="session"/>


There isn't actually much you could do reinvoking a text tag, unless you wish to append to the StringBuffer.


<h2g2j:text ref="query" scope="session">
AND J.DESC = '<%=jobDesc%>'
</h2g2j:text>



Which would be equivalent to doing

<h2g2j:text id="query" scope="session">
SELECT NAME, ADDRESS, JOBID
FROM EMPLOYEE E, JOBS J
WHERE E.EID = J.EID AND
E.STATE = '<%=state%>' AND
current_date - E.STARTDATE > <%=minExp%>
AND J.DESC = '<%=jobDesc%>'
</h2g2j:text>


Since the StringBuffer of the tag is associated with the java variable "query", you would invoke the StringBuffer with that variable:

<%
jdbcConnection.submit(query);
%>

1 comment:

  1. Both things are possible if you carry Michael Kors Handbags Wholesale. If you are a woman who goes for innovative designs, a designer Michael Kors Bags On Sale is perfect for you. Offering a huge selection of chic purses, handbags, shoes and accessories, Michael Kors Outlet Online Store celebrates womanhood in an entirely unique way. Michael Kors Factory Outlet Online Store At Wholesale Price are one of the most sought-after handbags worldwide. We all agree that diamonds are a woman's best friend; however Official Coach Factory Outlet Online are absolutely next in line. To Coach Outlet Sale aficionados, don't fret because we have great news: a discount Official Coach Outlet Online isn't hard to find. If you are a smart shopper looking for a good buy and great deals on your next handbag purchase, you can go to Official Coach Outlet Online.

    Friendly Links: Toms Shoes Womens | Toms Clearance

    ReplyDelete