• 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

Can I pass a bean to a javascript function within a html:iterate tag?

 
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
I am iterating over a collection of objects and creating radio buttons. I would like to use info from the ReportBean object to pass to an on click javascript call as follows:


I would guess that when compiled, the jsp would contain the actual bean values in the javascript call, but when I do a view source on the page, I see this:



instead of this:


I am guessing maybe I have a parenthasis wrong or some other syntax problem. Can anyone spot it? I have made this work before when the item value I am passing is an integer, but now with string values being passed, this is not working as I would expect.
 
Sheriff
Posts: 67747
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
Whenever you see JSP elements not interpreted and passed as part of the HTML source, you can bet that something is not configured correctly. Are you sure that you have the bean TLD properly declared?
 
Kim Kantola
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Bear,

I have this at the top of my jsp, is that what you mean?
<%@taglib uri="/tld/struts-bean.tld" prefix="bean"%>

Also, I do use bean:write in other spots of the page and those all resolve fine, its just when I use it inside a javascript method call upon an on click.
Kim
 
Bear Bibeault
Sheriff
Posts: 67747
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
Oh, yeah. I'm surprised you're not getting a translation error. You cannot use actions within the attribute values of another action.
 
Kim Kantola
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I guess I can use

But I thought including <%= %> was something that was recommended to avoid. Is it considered OK practice? If not, would you recommend a better way to access the bean value?

Thanks,
Kim
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Did you find a way to pass the <bean:write> tag to java script function?, If yes could you pl share the details. Am also stuck with same problem.

Regards,
Chandran
 
Ranch Hand
Posts: 329
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try something like this (with quotes) but say bye to scriplets,



OR your bean write should work if you use double quotes (the code you posted has single quotes). If it is still a problem, reply with js error
 
All of life is a contant education - Eleanor Roosevelt. 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