| |||||||||
Snippets as Struts taglibrary attribute
Snippets as Struts taglibrary attributeOften when you are combining presentation of collections of data with javascript, you may wish to take actions on the individual line in that collection. While in the below code Struts allows you to set thestyleId attribute with a mix of text and scriptlet, it does not for the onchange attribute.
Whatever is inside the onchange attribute (and many other) are simply not evaluated by the JSP engine and hence you'll have useless HTML such as
<input type="text" onchange="<%=row%>" ... />. Such HTML could be produced by code such as below:
Solution<logic:iterate indexId="row" ... <html:text styleId='<%="quantity_" + row%>' onchange="updateRow(<%=row%>)" indexed="true" ... /> // ILLEGAL CODE!! ...Fortunately, there is a hack around it which is to have only a scriptlet as the value for the onchange attribute.
<logic:iterate indexId="row" ...
<% String hack = "updateRow('"+row+"');"; %>
<html:text styleId='<%="quantity_" + row%>' onchange="<%=hack%>" ... />
...
CommentsIf you have any comments to this article, please drop me a mail at firstclassthoughts at gmail dot com please indicate if I can't publish whole or parts of your comment on the site.If you like this site consider Help spread the wordShare this post on your favorite social bookmarking sites:
The most recent contributions 28/07/09 Magic in mathematics II Fun with the number cyclic numbers, and specifically with 142857 as it is the smallest of such numbers. 13/07/09 My top 8 time-saving Firefox shortcuts This article presents my favorite top 8 time-saving shortcuts in Firefox 3.0 and Firefox 3.5. Get to know these and you'll be saving a lot of time. They have been ordered by "the element of most surprise" 20/05/09 Board Game Jungle speed / Arriba Review of the cool game "Jungle Speed" aka. "Arriba". 16/05/09 Danish Twin words "Twin words" are words that not only have multiple meanings, they must be composed next to each other in meaningful sentences. This article explores the concept of twin words. Nothing of interest? Try browsing the entire article archive... | |||||||||