• Post Reply Bookmark Topic Watch Topic
  • New Topic

Dynamic variable name in JSTL  RSS feed

 
Mal Charlton
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

Does anyone know how i can get a value (with a dynamic name, evaluated at runtime) off the request?

Here's an example...

In a Struts action, I add 2 attributes to the request:


Then in my JSP, i want to get the manager name as follows:



I'd like the final <c ut> to return "MrManager".

Is this possible with JSTL 1.0.4? If anyone knows, i'd really appreciate some help. This is bugging me out

Thanks.

Malcolm
[ May 09, 2005: Message edited by: Mal Charlton ]
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66144
144
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Mal J C",

We're pleased to have you here with us on the Ranch, but there are a few rules that need to be followed, and one is that proper names are required. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Thanks!
bear
Forum Bartender

P.S. When posting code, checking the 'disable smilies' box will keep your <cut> tags from looking so surprised.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66144
144
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Firstly,



you imply a relationship here but I see none. What is the significance of the hard-coded "1"? Is it the employee ID? There's no way of knowing.

Next,



performs no operation. "employee" is already on the request, why replace it with itself?

And,



you cannot nest actions (tags) within other tags like this.

If what you are trying to do is what I suspect you are trying to do: that is, use the property of a scoped variable as a way to look up another scoped variable, try something along the lines of:

 
Mal Charlton
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the quick reply, Bear

I'll address your points in order:

1. I've corrected my display name.
2. "1" was the manager ID in the example



3. I thought i had to explicitly declare the variable to be able to use it on the JSP, but now i know better. Thanks for the tip!


4.
This is probably what i'm looking for. However, my real problem is a bit more complicated...

Suppose i have this situation:


Now, on the JSP, how would i get "Bob" off the request using the Employee object? I'm not sure on the syntax. Would it be something like...



?
[ May 09, 2005: Message edited by: Mal Charlton ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!