• 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

bean property as html:link attribute value

 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
(The solution may be obvious. I may just be tired and not thinking clearly. Also, I suppose that the solution might be strictly JSP-related. If so, I'll move this thread.)
Using the logic:iterate tag, I'm iterating over an array.
For each component (bean) in the array, I'd like to use one of its properties to form the value of the styleId attribute of the html:link tag.

I'd like to replace that XXX with a property of the bean.
I've tried just inserting
<bean:write name="beanName" property="bar"/>
but it throws an exception (concerning an unterminated tag). I've tried inserting
<%= ((BeanType)beanName).getBar() %>
but this just gets interpretted as plain text. I've tried inserting
"<%= ((BeanType)beanName).getBar() %>"
but it throws an exception (concerning an unterminated tag).
So, how is this to be accomplished?
[ April 16, 2004: Message edited by: Dirk Schreckmann ]
 
Ranch Hand
Posts: 1258
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dirk,
What you should do depends on what version of JSP you are using.
If you are using JSP 2.0, you can set the value of the attribute something like ${bean.attribute}.
If you are using JSP 1.2 (or prior), then can do one of the following:
1) If you're not doing your JSP document as an XML document, you can do it as you are trying, and it should work.
2) If you're doing your JSP document as an XML document, you will need to wrap your html:link into two CDATA elements and in between use the expression to set the attribute's value.
It looks like you're going to need to do option (2), since you mentioned the compiler complaining about non-well-formed tags.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for your advice, Nathaniel. I'd meant to remember to mention that I'm developing to the JSP 1.2 spec (unfortunately). I tried a dozen combinations with CDATA tags, but I couldn't get anything to work.
In my original post, I left out something. I lied when I indicated that the JSP expression comprised the entire value used for the styleId attribute. In reality, I was trying to precede and succeed the expression with additional text. When I moved that additional text into the JSP expression with a couple of concatenations, it worked as expected and wanted.
So, in the end the construct that works, is one I initially claimed didn't - replace the XXX with <%= ((BeanType)beanName).getBar() %>
Shame on me for lying.
 
reply
    Bookmark Topic Watch Topic
  • New Topic