Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

TLD files variable element

 
Kevin Vdb
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I'm preparing for the OCWCD exam. At the moment I'm strubbeling with the <variable> element in TLD files.
What I'm trying to do is reconstruct a question from Enthuware in my project with the following code:


My Taglib:


and in my jsp:


However I'm getting the following error: org.apache.jasper.JasperException: /testTagLib.jsp(12,0) Attribute var invalid for tag advice according to TLD

Any help would be greatly appreciated!

Thanks in advance,
Kevin
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2419
95
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Kevin,

However I'm getting the following error: org.apache.jasper.JasperException: /testTagLib.jsp(12,0) Attribute var invalid for tag advice according to TLD

You are getting this error because you are declaring a variable that comes from an attribute (<name-from-attribute>), but you didn't decare the attribute var in your tag-entry. Have a look at my examples where I will declare 2 variables: one <name-from-attribute> and one <name-given>:

My TagHandler:
and my jsp:
creating an output of:
start|This is the name kevin of the tag|kevin|end

Regards,
Frits
 
Shashank Sharma
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Frits ,
I have the doubt on the same example.
I am using the code snippet as used by kevin but without the nested variables and having only one attribute user.
I have kept <body-content>tag as empty
and am using the tag as

but it says " Expression language not allowed in a template text body".

thanks






 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2419
95
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but it says " Expression language not allowed in a template text body".

This is typically the case when you define a <jsp:attribute> without a <jsp:body> inside a custom tag.

However you defined the body-content as being empty so the container should allow the absence of the <jsp:body>, see this section of the specs:
JSP.5.11 <jsp:body>
Normally, the body of a standard or custom action invocation is defined implicitly as the body of the XML element used to represent the invocation. The body of a
standard or custom action can also be defined explicitly using the <jsp:body> standard action. This is required if one or more <jsp:attribute> elements appear in the
body of the tag. If one or more <jsp:attribute> elements appear in the body of a tag invocation but no <jsp:body> element appears or an empty <jsp:body> element appears, it is
the equivalent of the tag having an empty body.


You have two options now:

create an empty <jsp:body>
or
use the attribute in the way you have seen before:


Regards,
Frits
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic