• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Struts html:select error

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a code sniblet below. My issue is this. When I attempt to pass a script variable into a function it is not being dereferenced. What gets passed to the function is <%=index%>, rather then the value of the variable index. Any ideas why? This syntax works with other html tags and I believe it has something to do with the struts html:select tag. Attempting to use double quotes or no quotes results in a complilation error. Thank for any help.


<SCRIPT>
function performActions(id)
{
creditForm.id.value=id;
creditForm.submit();
}
</SCRIPT>
<% String index = "1" ; %>
<html:select property="<%=property%>" onchange="performActions('<%index%')">
 
Ranch Hand
Posts: 354
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
it's performActions('<%=index%>') not performActions('<%index%')>
 
Sheriff
Posts: 17698
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
and they're usually called "code snippets"
[ May 17, 2005: Message edited by: Junilu Lacar ]
 
chris hart
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
actually the lack of the "=" is a type o. The code does not function properly with the "=" added to <%index%>
In debugging I can see that <%=index%> is what is contained in the var.
 
chris hart
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Below are two drop down boxes. One using the struts html taglib. The struts drop down box does not dereference the var when it is passed to the javascript function. The non struts drop down works as expected. Can anyone explain why the struts html:select acts differently and how I can get it to dereference the var
Non struts dropdown:
<select name="<%=property%>" onchange="javascript erformActions('<%=property%>')">
<option value="include">Include</option>
<option value="payoff">Payoff</option>
<option value="payoffWithAssets">Payoff with Assets</option>
<option value="exclude">Exclude</option>
</select>

Struts drop down:
<html:select property="<%=property%>" onchange="javascript erformActions('<%=property%>')">
<html ption value="include">Include</html ption>
<html ption value="payoff">Payoff</html ption>
<html ption value="payoffWithAssets">Payoff with Assets</html ption>
<html ption value="exclude">Exclude</html ption>
</html:select>
 
chris hart
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I found a solution. The variable would not get derefernced so I used the "this" keyword, now the value of the object gets passed.

<html:select property="<%=property%>" onchange="javascript erformActions(this.name)">
<html ption value="include">Include</html ption>
<html ption value="payoff">Payoff</html ption>
<html ption value="payoffWithAssets">Payoff with Assets</html ption>
<html ption value="exclude">Exclude</html ption>
</html:select>
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The reason struts didn't decode your <%=index%> scriptlet is that struts has an "all or nothing" policy on scriptlets in attributes. This means that if the entire attribute is a scriptlet, struts will decode it, but if only part is a scriptlet, struts will not decode it.

If you had written

<%="performActions(" + index + ")"%>

It would have worked.
 
Space pants. Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic