Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Custom Tag & standard action doubt?

 
kumar chandra
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what happens to custom tags and standard action of a jsp file during translation.where these items goes during the translation.
 
Anupama Ponnapalli
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Best way to know is to look at the java source file generated for a JSP that uses custom tags/beans. I found it at this location on my workstation
$tomcat_home\work\Catalina\localhost\<appname>\org\apache\jsp\HelloWorld_jsp.java

I have an example of SimpleTagSupport here.

Given a tag class simplemodel.HelloWorldTag extending SimpleTagSupport, the java source translated from jsp looked like this:

.. _jspService() ...
{
...
out.write("\r\n");
out.write("\r\n");
out.write("\r\n");
out.write("<B>Test 1</B>\r\n");
if (_jspx_meth_sm_helloWorld_0(_jspx_page_context))
return;
}

with the method that actually invoked the tag looking like this:

1 private boolean _jspx_meth_sm_helloWorld_0(PageContext _jspx_page_context)
2 throws Throwable {
3 PageContext pageContext = _jspx_page_context;
4 JspWriter out = _jspx_page_context.getOut();
5 // sm:helloWorld
6 simplemodel.HelloWorldTag _jspx_th_sm_helloWorld_0 = new simplemodel.HelloWorldTag();
7 _jspx_th_sm_helloWorld_0.setJspContext(_jspx_page_context);
8 _jspx_th_sm_helloWorld_0.doTag();
9 return false;
10 }

Given what we know about the lifecycle, the container has to
a) create an instance of the tag - line 6
b) set the jsp context on the tag object line - line 7
c) call the setParent if it is nested and call the set attributes if they are used in the invocation - not applicable
d) invoke the doTag method of the tag's class - line 8

Please note that the actual source might vary depending on the vendor, this is just an example with tomcat 5.5

For java beans, the use bean tag is translated as below:

entity.Employee emp = null;
synchronized (_jspx_page_context) {
emp = (entity.Employee) _jspx_page_context.getAttribute("emp", PageContext.PAGE_SCOPE);
if (emp == null){
emp = new entity.Employee();
_jspx_page_context.setAttribute("emp", emp, PageContext.PAGE_SCOPE);
}
}

The jsp looked like this:
<jsp:useBean id="emp" class="entity.Employee" />

Does this answer your question?
 
kumar chandra
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks A Lot Anupama..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic