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

JSPFragment

 
Nikhil Jain
Ranch Hand
Posts: 392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Ranchers, I was going thru the JSP fragment in page 502(HFS). But I am finding it difficult to grasp the concept. What exactly does JSP Fragment do. I mean...is it only for SimpleTagSupport.
 
Niranjan Deshpande
Ranch Hand
Posts: 1277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSP fragments have .jspf extensions.
These are incomplete jsp pages.
you typically name a jsp with a .jspf ectension when ypu want to include that into another MAIN JSP (whose source code has a html and body tags). If you out the same tags for the included jsp alse, the resultabt jsp will have nested html and body tags which is incorrect.

Note that to enable .jspf stuff you need to add a declaration in web.xml
refer to HFSJ chapter 8 for this

Correct me if i m wrong
 
Narendra Dhande
Ranch Hand
Posts: 951
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

The JSP fragment is JSP code without scripting codes. Actually JspFragment is Object which encapsulate JSP code into it that can be invoked as many times as needed.

The JSP fragments can be in the body of the SimpleTag handler. The fragment in the body is executed when the <jsp oBody> tag is encountered.




The invokation of tag in JSP file is

<%taglib prefix="test" tagdir="/WEB-INF/tags" %>
<test:tag1>
This body is treated as JSP fragment. It should not contain scripting. and the body-content should be "scriptless"
</test:tag1>



Also you can pass JSP frgment as attribute and the fragment can be executed by <jsp:invoke > standard tag.



The invokation of tag in JSP file is

<%taglib prefix="test" tagdir="/WEB-INF/tags" %>
<test:tag2>
<jsp:attribute name='frag1'>
This attribute value is treated as JSP fragment. It should not contain scripting.
</jsp:attribute>
</test:tag2>

You can also use the jsp fragment in Simple and custom tags in the attribute values. To do this you have to set the foollwing attribute options in tld file while defining the tag .



Assuming that the setter method in the tag implementation set the frag2 attribute in the tag correctly,
Then you can inoke this fragment attribute using the

frag2.invoke(null);

Hope this help
[ July 10, 2006: Message edited by: Narendra Dhande ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic