File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes Is nested c:out  possible? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Is nested c:out  possible?" Watch "Is nested c:out  possible?" New topic
Author

Is nested c:out possible?

Vicky Mohan
Ranch Hand

Joined: Oct 14, 2004
Posts: 130
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 ]
Nathaniel Stoddard
Ranch Hand

Joined: May 29, 2003
Posts: 1258
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.


Nathaniel Stodard<br />SCJP, SCJD, SCWCD, SCBCD, SCDJWS, ICAD, ICSD, ICED
Vicky Mohan
Ranch Hand

Joined: Oct 14, 2004
Posts: 130
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.
Yuriy Zilbergleyt
Ranch Hand

Joined: Dec 13, 2004
Posts: 429
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
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61594
    
  67

Here's a small example that you can study in order to adapt the techniques to your own use:



[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61594
    
  67

P.S. The example assumes JSP 2.0. Some adjustments necessary if not.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61594
    
  67

P.P.S. Be sure to click the 'disable smilies' checkbox when posting code to avoid all those 's.
Vicky Mohan
Ranch Hand

Joined: Oct 14, 2004
Posts: 130
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

Joined: Dec 13, 2004
Posts: 429
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

Joined: Oct 14, 2004
Posts: 130
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

Joined: Dec 13, 2004
Posts: 429
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

Joined: Oct 14, 2004
Posts: 130
I am using JSP 1.2 . Will that be an issue ??
Yuriy Zilbergleyt
Ranch Hand

Joined: Dec 13, 2004
Posts: 429
Yes, probably.

Try

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

-Yuriy
[ August 26, 2005: Message edited by: Yuriy Zilbergleyt ]
Vicky Mohan
Ranch Hand

Joined: Oct 14, 2004
Posts: 130
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

Joined: Dec 13, 2004
Posts: 429
Assuming these are all bean-style properties, can't it be done the same way as the earlier problem?



-Yuriy
Vicky Mohan
Ranch Hand

Joined: Oct 14, 2004
Posts: 130
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
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61594
    
  67

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
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61594
    
  67

THanks a lot for your help, Yuriy.


You're welcome.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Is nested c:out possible?