Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Passing jstl to javascript function

 
john mattucci
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><cut value="${access.action}"/></td>
<td><html:checkbox property="approve" indexed="true" name="access" onclic="chkApprove(this,this.form, <cut 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, <cut value="${access.action}" />)"/>

Thank you for your time
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65223
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This has nothing to do with the fact that the <cut> 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
Author and ninkuma
Marshal
Pie
Posts: 65223
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • 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
 
Merrill Higginson
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic