This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes What are <variable> & <name-from-attribute> tags in the TLD?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "What are <variable> & <name-from-attribute> tags in the TLD??" Watch "What are <variable> & <name-from-attribute> tags in the TLD??" New topic
Author

What are <variable> & <name-from-attribute> tags in the TLD??

Sourin K. Sen
Ranch Hand

Joined: May 02, 2006
Posts: 86

Here's a question from a mock exam of enthuware :

Assuming that the tag library shown in the exhibit is imported with the prefix 'item'. Which custom tag invocation outputs the contents of the variable exported in the 'price' tag?
The options are :

  • <item:price itemcode="IT001" />
    ${var}
  • <item:price itemcode="IT001" var='cost' >
    ${cost}
    </item:price>
  • <item:price itemcode="IT001" >
    ${var}
    </item:price>
  • <item:price itemcode="IT001" var='cost' />
    ${cost}
  • <item:price itemcode="IT001" var='cost'>
    <%=cost%>
    </item:price>
  • <%=cost%>
    <item:price itemcode="IT001" var='cost'></item:price>


  • And here is the exhibit for this question :

    <?xml version="1.0" encoding="UTF-8" ?>
    <taglib xmlns="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance:
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"
    version="2.0">
    <tlib-version>1.0</tlib-version>
    <short-name>item</short-name>
    <uri>http://abc.com/tld/item.tld<uri>
    <tag>
    <name>price</name>
    <tag-class>com.abc.PriceTag</tag-class>
    <body-content>scriptless</body-content>
    <variable>
    <name-from-attribute>var</name-from-attribute>
    <scope>NESTED</scope>
    </variable>

    <attribute>
    <name>itemcode</name>
    <required>true</required>
    <rtexprvalue>false</rtexprvalue>
    <attribute>
    <tag>
    <taglib>


    Can anyone explain me this <variable> & <name-from-attribute> tag??
    I didn't come across these tags while reading HFSJ. Perhaps I might have missed something...

    Regards,<br />Sourin.
    Sourin K. Sen
    Ranch Hand

    Joined: May 02, 2006
    Posts: 86
    Anyone please??
    Poonam Agarwal
    Ranch Hand

    Joined: May 12, 2008
    Posts: 323
    hello,

    What is the correct options??? I am not clear but i guess <variable> tag is specified here is used to expose the value of a attribute specified..

    I am not sure.... anyone please clear this doubt



    thanks in advance


    Thanks <br />Poonam Agarwal SCWCD 86%
    Sourin K. Sen
    Ranch Hand

    Joined: May 02, 2006
    Posts: 86
    Poonam Agarwal wrote:What is the correct options???

    The correct option is :

    <item:price itemcode="IT001" var='cost' >
    ${cost}
    </item:price>


    But my questions are :
    1. Are all of the elements and sub-elements of a TLD file are covered in the exam?
    2. Where to get proper info on these elements apart from the JSP Spec (its kinda messy and hard to read)
    Poonam Agarwal
    Ranch Hand

    Joined: May 12, 2008
    Posts: 323
    totaly agree with you.... JSP spec have the details of these tag but its very hard to get it... I tried to mugging but won't help


    Poonam Agarwal
    Ranch Hand

    Joined: May 12, 2008
    Posts: 323
    anybody else??
    Poonam Agarwal
    Ranch Hand

    Joined: May 12, 2008
    Posts: 323
    hello Sourin,

    I just seen an example showing the use of <variable> tag in the TLD. I hope this will help you to clera your doubts , atleast little bit

    This question is from Enthuware mock

    You are using a tag library with prefix "generator", which supports a tag named "random". This tag generates a random number and sets it to a variable named "value". Which of the following will output this value in the page?

    1. <generator:random>value</generator:random>
    2. <generator:random><%=value%></generator:random>
    3. <generator:random><% int value;%> <%=value%></generator:random>
    4. None of the above.

    the correct option is 2. the explaination given is

    The variables that are set by the custom tag are defined in customtag TagExtraInfo class. For example, in this case, the ExtraInfo impl for this tag should return an array of VariableInfo objects, an object of which will be same as:

    new VariableInfo("value", "String", true, VariableInfo.NESTED);

    true => a new variable 'value' will be declared.

    NESTED => Between the start tag and the end tag.

    Another way to specify that a custom tag exposes a variable to the JSP page is through the <tag> element of the TLD. For example, the TLD for the above tag may contain:

    <tag>
    ...
    <variable>
    <name-given>value</name-give>
    <variable-class>java.lang.Double</variable-class>
    <scope>AT_BEGIN</scope>
    </variable>
    </tag>
    </tag>

    I guess you can ignore some of initial details about classes and all.

    Sourin K. Sen
    Ranch Hand

    Joined: May 02, 2006
    Posts: 86
    Thanks a lot Poonam. That clears up the issue of how to use it and why to use it. But still one question is left ( I haven't gone through the SCWCD Exam Spec thoroughly), is it covered on the exam?

    What else is covered on the exam which is not covered by HFSJ?

    I dont have much time left with me as I am going to give the exam in a few days time and so it would be very helpful for me if someone can list out the things that haven't been covered by HFSJ but are there for the exam.

    Thanks a lot in advance.
    Poonam Agarwal
    Ranch Hand

    Joined: May 12, 2008
    Posts: 323
    Sourin,

    Don't worry. there is nothing that HFSJ dosen't cover. It meant to clear the SCWCD with flying colors.

    I am sure you don't need anyhting else if you cover that book completely. you will cleat the exam very easily. Just refer the API for important method signataure and related specification.



    All the VERY BEST for your exam
     
     
    subject: What are <variable> & <name-from-attribute> tags in the TLD??
     
    Similar Threads
    Problems making Struts/JSTL 1.2 site work with JSTL 2.0
    how comws varaible in the tag
    TLD files variable element
    problem with running Classic tags