This week's book giveaway is in the Open Source Projects forum.
We're giving away four copies of Spark in Action and have Jean-Georges Perrin on-line!
See this thread for details.
Win a copy of Spark in Action this week in the Open Source Projects forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Custom Tag & standard action doubt?

 
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.
 
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..
 
No. No. No. No. Changed my mind. Wanna come down. To see this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic