• Post Reply Bookmark Topic Watch Topic
  • New Topic

Need JSTL syntax help

 
Dheeman Basu
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • 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} }" />
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65522
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • Quote
  • Report post to moderator
Ignore the double quote question. I created the problem. Thanks for solving the case once again.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65522
105
IntelliJ IDE Java jQuery Mac Mac OS X
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!