• Post Reply Bookmark Topic Watch Topic
  • New Topic

Setting variables from tagfiles with "var-from-attribute"

 
Mike McNally
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've been trying to do what I thought was simple - have a tag into which I pass a variable name so that the tag can stuff a useful value into it. I've followed the simple examples I've found (and my tag is as simple as the simplest), but even with an exact transcription of the example from the Oracle site I get an error from Jasper:

PWC6242: The attribute directive (declared in line 3 and whose name attribute is "var", the value of this name-from-attribute attribute) must be of type java.lang.String, is "required" and not a "rtexprvalue".


Now setting aside the questionable grammar of that error, it seems to be telling me that the attribute to which "var-from-attribute" refers has to be a String (fair enough), has to be required (also fair) but then has to have "rtexprvalue" set to false. Well, that seems a little lame, but in any place I can imagine using my particular tag I won't be wanting to do that anyway.

So if I change my tagfile such that my attribute is explicitly marked withthen Jasper is OK with the tagfile. However, when I try to use the tag with a plain stringJasper complains that I'm trying to use an expression for the value of the attribute. Well, I'm not, as far as I can tell; it's just the text "formId". ([edit] Never mind - it does not actually give me that error - I think another problem was causing that)

This is supposed to work, right? For what it's worth I'm seeing this in Jetty 1.7 and Glassfish v2, exactly the same behavior.

Here's my complete tag (without the tweaks to the "var" attribute mentioned above):
Also, Hi Bear.

 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mike! Unfortuntely, I have no experience using the "variable name-from-attribute" directive. To be honest, I've always just used <c:set> within tags, but that doesn't give you any of the scope control that you might need. Sorry to be so useless.

Welcome to the Ranch!
 
Mike McNally
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well it seems to work fine, but I guess my remaining question is why neither the example code nor any docs I've seen mention the fact that the attribute supplying the name has to be required and cannot be an expression value. However I'll forget about it pretty soon as I've got plenty of other stuff to worry about :-)
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mike McNally wrote:... as I've got plenty of other stuff to worry about :-)


Don't we all!

P.S. PM me. We should meet for lunch soon.
 
Justin Nauman
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To be honest, I couldn't tell from the conversation if you had gotten this working or not, but I had EXACTLY the same experience today.

After toying around with this a bit today, I came to the same conclusion as you that I did in fact need to set the rtExprvalue="false" for what would be your "var" attribute.

Another thing that was not clear in the documentation that I had found was that if you want to use the variable inside the tags, you need include the <jsp:doBody/> tag after the <c:set var="aliasName" value="whatever" />.

If this is "old news" I apologize, I have just recently started using Tag 2.0 files.

Cheers,
Justin N.
Chicago, IL
 
Mike McNally
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Justin Nauman wrote:To be honest, I couldn't tell from the conversation if you had gotten this working or not, but I had EXACTLY the same experience today.

After toying around with this a bit today, I came to the same conclusion as you that I did in fact need to set the rtExprvalue="false" for what would be your "var" attribute.

Another thing that was not clear in the documentation that I had found was that if you want to use the variable inside the tags, you need include the <jsp:doBody/> tag after the <c:set var="aliasName" value="whatever" />.


Hmm that's good to know - in my case the whole purpose of the tag was just to set the variable, so I didn't need it inside.

And yes I got it working. Thanks!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!