• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

The attribute directive in tag files.

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
If an attribute is not declared using the attribute directive where will it be created tagScope or in the including page's pageScope ?
if it is declared using an attribute directive which scope is it attached to ?
 
Ranch Hand
Posts: 437
Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Supun. If we don't declare attribute directive in tag file, and if try to call through jsp, exception will occur.
If declared in tag file, the attribute will be set in page scope.
 
Supun Dewaraja
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
my problem is does the tag file have its own page scope or is it the including file's page scope. Because all tag attributes go out of scope when the tag completes how can that happen if its an attribute bound to the including file's page scope ?
 
Chinmaya Chowdary
Ranch Hand
Posts: 437
Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Supun. Can you please explain your problem with an example?
 
Supun Dewaraja
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is my jsp


and my tag file sri.tag in "/WEB-INF/tags" is


this prints

The subtitle is



what could be the problem.
 
Chinmaya Chowdary
Ranch Hand
Posts: 437
Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Supun.
Here 'subTitle' will not be visible in jsp file. The attribute 'subTilte' will be set in tag file with page scope. It will visible to only sri.tag file.
If you see the generated source file it will be clear.
 
Supun Dewaraja
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh ok got it so the body is evaluated against the main jsp page scope.
Thanks for the help Chinmaya
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I believe you need to use the <%@ variable directive. See:

http://java.sun.com/javaee/5/docs/tutorial/doc/bnama.html#bnamj
 
Chinmaya Chowdary
Ranch Hand
Posts: 437
Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Bruce. Can you please tell, the purpose of variable directive?
 
Supun Dewaraja
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah that worked thanks Bruce I am wondering whether this is on the exam Head First slightly mentions the variable directive in the questions though.
here is the jsp


and the sri.tag


It produced the result

The subtitle is The Da Vinci Code



The variable directive is used to pass back values (kind of like a return from a method) to the main JSP from the tag file.
more here webpage
 
Bruce Phillips
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Glad you figured out how to use it.

The variable directive does show up on my Enthuware SCWCD mock exams.

Here's another example for people to use (this one uses the name-from-attribute and scope of "AT_BEGIN")

YearBorn.tag



TagFileTest.jsp


The <@ variable name-from-attribute="var" scope="AT_BEGIN" alias="yearBorn" %> means when the tag is called the value for the var attribute will be the name of the variable to set in the calling page. The alias="yearBorn" means in the tag file whatever value is given to yearBorn will be the value given to the var attribute's value in the calling page (in my example the var="brithYear".

The scope="AT_BEGIN" means that the birthYear value will be available from the beginning of the call to the tag file on through the rest of the calling page.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic