• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Simple tag question

 
Paolo Metafune
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've two question to present you.

1)Can you tell me which is the use of the <variable> sub element of <tag> in a TLD ?. I mean that if i want to send back a variable to the calling page of a custom tag, in the tag handler i can just put the variable in the proper scope and then the calling page can use the variable retriving it fron the same scope. Therefore: what does the <variable> sub element for me ?

2)What is the mean of the "tagdependent" value for a custom tag body content ?
For instance is possible to say that in a Simple tag the body, when isn't empy, is tag dependent ? The body is infact evaluated only if the handler calls the invoke method on the jspbody object. I mean that if want to use the body in another way is sufficient for me not to call that method. So a scriptless body content may be considered tagdependent.

Thank you.
 
Sergey Tyulkin
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) Using <variable> is much more flexible way to work with variables. You can pass variable name as a tag parameter, you can define the scopes of visibility of the variable. And all of this is done automatically. For example, when you will use you approach, you will have to implement some synchronization mechanism. When you will use <variable> tag, the synchronization will done for you in predefined, synchronized manner.
2) Again, tagdependent is a more flexible way to work with situations, when tag must use its body verbatim. Your approach will also work, but you (again)will need some hand code, that can be done automatically using tagdependent value for body-content. More over, tagdependent is very useful for such things, when you use Standard tags (not SimpleTags).
 
Paolo Metafune
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Excuse me Sergey but i don't understand some things.

1)I have declared a variable in this way : <variable>
<name-given>expVar</name-given>
<scope>NESTED</scope>
</variable>
How do i set the variable value in the tag handler ? I used this instruction in my tag handler "getJspContext().setAttribute("expVar","2");"
But naurally it sets the value in the page scope and in the calling page i can refer it, after my simple tag end , also if in the tld the scope is "NESTED" and i should see it only in the body of the tag.
Furthermore i dont' understand what you mean when you speak of variable synchronization.

2) In a custom tag how do i obtain the body content if it is specified as tagdependent. In the same way as for scriptless body or in a different manner ? Can you provide a simple example ?

Thank you
[ August 31, 2005: Message edited by: Paolo Metafune ]
 
Sergey Tyulkin
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) There was a type in my message - this: "the synchronization will done for you in predefined, synchronized manner" should read like this: "the synchronization will done for you in predefined, standard manner".
The synchronization takes part, when variable value is transferred to scripting variable. For example, here
<myprfx:mytag>
<%= expVal%>
</myprfx:mytag>
Here we don't use attribute mechanism, but scripting variables.
As for NESTED variables, the specifiaction says, that variable must be accessible only in the body of the tag, so you are using incomplete JSP 2.0 specification implementation. However, I wonder, are there some "complete" implementations.
2)When you call invoke on JspFragment, for scriptless body you will get evaluated body of the tag, for tagdependent body you will get verbatim body tag.
 
Paolo Metafune
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Sergey. I only wanted to add that the problem of NESTED variable visible after the end of tag doesn't happen if i use tag file instead of SimpleTag.
My Container is Tomcat 5.0.19.


Bye.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic