• 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

Is nested c:out possible?

 
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey All,

I have a crazy requirement. I need to display a value availble in request, but the KEY is a combination of two values. The first value is constant but the second value is dynamic and this CODE is within a LOOP.

Suppose if the key is KEY1, KEY is CONSTANT but 1 is dynamic and is available in request as "ONE".

I tried this by using the following code

<c ut value="{KEY<c ut value='${ONE}'/>}"/>

But it does not work.

Please let me know if this is possible in JSTL ..
[ August 26, 2005: Message edited by: Bear Bibeault ]
 
Ranch Hand
Posts: 1258
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think the reason it won't work is because you're trying to nest a custom tag in a custom tag. If you were putting your c ut in a regular html tag, it would be just fine (assuming you're not doing JSP documents, aka XML format).

However, I think that c ut has the ability to save the value to a variable instead of sending it to the response. At that point, you could reference the variable in the "outside" c ut. Check out the docs for c ut, because I can't recall what the name of the attribute is that would allow you to do this.
 
Vicky Mohan
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
THanks for your reply.

I have made a search for an example but have not succeeded so far.

If you can provide an example, it will be great.
 
Ranch Hand
Posts: 429
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hmm, this would be so much easier if EL had an operator for string concatenation. You could still write your own EL function for concatenation, and then it becomes a simple case of:

${requestScope[myfunc:concat("KEY", ONE)]}

-Yuriy
 
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
Here's a small example that you can study in order to adapt the techniques to your own use:

 
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
P.S. The example assumes JSP 2.0. Some adjustments necessary if not.
 
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
P.P.S. Be sure to click the 'disable smilies' checkbox when posting code to avoid all those 's.
 
Vicky Mohan
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
THanks, Bear.

I am trying to print the value in a text box.

<input type="text" name="Name" size="18" value="${requestScope[keyName]}" >

But it is not getting replaced.

I tried to use C UT too, but it didnt help either.

Is there anything i am missing ???
 
Yuriy Zilbergleyt
Ranch Hand
Posts: 429
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you use <c:set> as Bear suggested? What did you put in it? We can't very well tell you if you're missing anything when you don't give us all the relevant code!

-Yuriy
 
Vicky Mohan
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sure, i can furnish the required code ..

<c:set var="keyTest" value="1"/>
<c:set var="keyName" value="Key${keyTest}"/>

In Request, we have value for attribue "Key1"

<input type="text" name="Name" size="18" value="${requestScope[keyName]}" >
[ August 26, 2005: Message edited by: Mohen Vijay ]
 
Yuriy Zilbergleyt
Ranch Hand
Posts: 429
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Works for me:



Try closing the browser window and going directly to the page. Sometimes IE Doesn't refresh default input values properly.

-Yuriy
 
Vicky Mohan
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using JSP 1.2 . Will that be an issue ??
 
Yuriy Zilbergleyt
Ranch Hand
Posts: 429
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, probably.

Try

<input type="text" name="Name" size="18" value="<c:out value="${requestScope[keyName]}"/>" >

-Yuriy
[ August 26, 2005: Message edited by: Yuriy Zilbergleyt ]
 
Vicky Mohan
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for all your help.

I had the sample code working..

But i ran into another issue, with a different scenario ..

I have an Object AAAA, that has another object BBBBB with an attribute ATTR1, ATTR2.

As always for me, attribute ATTR1 is not availble straight forward. I need to construct it using two String ..

Object AAAA is available in request

Any thoughts on how this can be implemented ???
[ August 26, 2005: Message edited by: Mohen Vijay ]
 
Yuriy Zilbergleyt
Ranch Hand
Posts: 429
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Assuming these are all bean-style properties, can't it be done the same way as the earlier problem?



-Yuriy
 
Vicky Mohan
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
THanks a lot for your help, Yuriy.

I got it working .....

Can you suggest any good websites for getting more information of the SYNTAX etc for JSTL ...
 
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
Get ahold of the JSTL specification for the version you are using. With JSP 1.2 you should be using JSTL 1.0.
[ August 26, 2005: Message edited by: Bear Bibeault ]
 
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

THanks a lot for your help, Yuriy.



You're welcome.
 
Did you miss me? Did you miss this tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic