Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Passing jstl to javascript function

 
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to pass jstl to javascript however when I attempt the following I get a syntax error

<c:forEach var="access" items="${dynamicArrayForm.map.access}">
<tr
<td><c:out value="${access.action}"/></td>
<td><html:checkbox property="approve" indexed="true" name="access" onclic="chkApprove(this,this.form, <c:out value='${access.action}' />)"/></td>

</tr>
</c:forEach>

and when I change the bold to double quotes I get Error: Attribute: ${access.action}" is not a valid attribute name

<html:checkbox property="approve" indexed="true" name="access" onclic="chkApprove(this,this.form, <c:out value="${access.action}" />)"/>

Thank you for your time
 
Marshal
Posts: 67451
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This has nothing to do with the fact that the <c:out> action is embedded in a Javascript snippet, but rather, because you are attempting to use a custom action in the attribute of another custom action.

This, you cannot do.

Forum instructions state that you should let us know what version of JSP and JSTL you are using.

Now would be a good time.

P.S. Also, please use UBB code tags to preserve the formatting of any posted code.
[ August 02, 2006: Message edited by: Bear Bibeault ]
 
john mattucci
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSTL 1.0
JSP 2.3

Sorry how would I go about doing what I'm trying to do in a better way
[ August 02, 2006: Message edited by: john mattucci ]
 
Bear Bibeault
Marshal
Posts: 67451
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no JSP 2.3. I assume you mean Servlets 2.3 and JSP 1.2?

What container are you using?

The answer is dependent upon the JSP version.
[ August 02, 2006: Message edited by: Bear Bibeault ]
 
john mattucci
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oops sorry yes that would be jsp 1.2. Container would be Oracle 10.1.2
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can fix this by using the Struts-el version of the <html:xx> tags.

To do this, change your taglib declaration to:

<%@ taglib uri="http://jakarta.apache.org/struts/tags-html-el"; prefix="html" %>

and make sure that struts-el.jar is in your WEB-INF/lib directory.

You can then write:

<td><html:checkbox property="approve" indexed="true" name="access" onclic="chkApprove(this,this.form, ${access.action})"/></td>
[ August 02, 2006: Message edited by: Merrill Higginson ]
 
john mattucci
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Awesome that worked. I just had to add \' around the expression i.e.



because without it I was getting a javascript runtime error 'string' is undefined.
[ August 03, 2006: Message edited by: john mattucci ]
 
Don't touch me. And dont' touch this tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
    Bookmark Topic Watch Topic
  • New Topic