• 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

Need JSTL syntax help

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have two beans in request context bean1 and bean2 (say).

One of the properties of bean1 is prop1 with value val1. Business logic ensures that bean2 is going to have a property named val1 with value val2.

Objective is to display the value val2 on the page.

Can someone help me with suitable jstl code?

<c:out value="S{bean1.prop1}" /> works, prints val1

<c:out value="S{bean2.val1}" /> works, prints val2

But I need something generic like <c:out value="S{bean2.${bean1.prop1} }" />
 
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
$, not S.

The ${} surrounds the entire EL expression -- it's not some sort of fetch operator so it is never nested.

If by "S{bean2.${bean1.prop1} }" you intend to fetch the property of bean2 whose name is the evaluation of bean1.prop1, then the correct syntax is: ${bean2[bean1.prop1]}
 
Dheeman Basu
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It works! thanks for quick response.
Sorry for the dollar and S confusion. That is something my editor is doing.

But I have a small problem still. The value is showing up as "val2" instead of just val2. How do I get rid of the double quotes?
 
Dheeman Basu
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ignore the double quote question. I created the problem. Thanks for solving the case once again.
 
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic