Forums Register Login

Dynamic variable name in JSTL

+Pie Number of slices to send: Send
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 ]
+Pie Number of slices to send: Send
"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 <c:out> tags from looking so surprised.
+Pie Number of slices to send: Send
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:

+Pie Number of slices to send: Send
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 ]
If you try to please everybody, your progress is limited by the noisiest fool. And this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 13062 times.
Similar Threads
Scripting with JSTL Core tags.
help with logic:iterate struts tag
How to do database pagination using JSTL tags
IMP c:remove doubt
how to use scope in target version of c:set
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 07:17:10.