• 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

how to pass a string and variable as value on a tag?

 
Ranch Hand
Posts: 37
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi there,

can someone please tell me why this is not working in JSP?: <bean:message key="col.<%=rowNum%>"/> i'm trying to get the rowNum dynamically, if I hardcode it it works i.e key="col.row2" so
also if I print <%=rowNum%> on its own it works so I know the variable is valid, but the combination of the string and the variable isn't working, how do I fix this?

I've also tried:
"col."<%=rowNum%> and
key=col."<%=rowNum%>"

No luck.

Thanks for the help in advance.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When using discredited scriptlet expressions in a custom tag value, the expression must be the entire value.

Scriptlets have been discredited for almost 10 years now. Time to update your JSP knowledge and use the EL and JSTL instead. EL expressions, by the way, do not have this attribute value limitation.
 
Klament J. Kruoghst
Ranch Hand
Posts: 37
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Bear thanks for your comment.

Would that just be instead of using <%= %> use ${}? so the expression would become: <bean:message key="col.${rowNum}"/>? i tried that before but it doesn't work.
I even tried just printing ${rowNum} and it doesn't print anything while doing <%=rowNum%> does work, so that's why i'm sticking with it.

Would you be able to help me either make it right using EL/JSTL or just how to re-write the expression with scriplet? by the way we use java 1.4

Thanks
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can't just replace scriptlet expressions with the EL if the rest of the page is still using scriptlets. For example, rownum is a scripting variable set by a scriptlet elsewhere on the page, right? That has to go as well. You really need to get up to speed on proper web app structure (using servlet controllers to do the data processing) as well as the JSTL and EL.

Meanwhile, you can try something like: to get around the current problem.

But, please, for your own sake, move away from 2001-style code and catch up to 2011!
 
Klament J. Kruoghst
Ranch Hand
Posts: 37
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'd definitely love to be coding with that if that's best practice but the whole application code is written using scriplets, I can't start mixing it up so please bear with me using something so old

I did the change and here's my current situation:
1) <h1><bean:message key="<%= "col." +rowNum %>"/></h1>
is printing nothing and this is what i see in the html source code: <h1><bean:message key="col.row2"/></h1>

That same line in my JSP (without using variable):
2) <h1><bean:message key="row1.col2"/></h1>
does get evaluated and prints the value I want.

Therefore it looks like (1) is not being evaluated, how can that be corrected?

Thanks in advance.

EDITED: I fixed it by declaring somewhere else the

I dislike it but if there's no choice then i have to split it.
Thanks bear for your help on this.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As <bean:message> is not a standard JSP tag, this has been moved to the Struts forum to determine why it's behaving badly.
reply
    Bookmark Topic Watch Topic
  • New Topic