Two Laptop Bag*
The moose likes Struts and the fly likes Struts html:select error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts html:select error" Watch "Struts html:select error" New topic
Author

Struts html:select error

chris hart
Greenhorn

Joined: Oct 09, 2003
Posts: 9
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%')">
alan do
Ranch Hand

Joined: Apr 14, 2005
Posts: 354
it's performActions('<%=index%>') not performActions('<%index%')>


-/a<br />certified slacker...yes, my last name is 'do' - <a href="http://www.luckycouple.com" target="_blank" rel="nofollow">luckycouple.com</a>
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4456
    
    6

and they're usually called "code snippets"
[ May 17, 2005: Message edited by: Junilu Lacar ]

Junilu - [How to Ask Questions] [How to Answer Questions]
chris hart
Greenhorn

Joined: Oct 09, 2003
Posts: 9
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

Joined: Oct 09, 2003
Posts: 9
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

Joined: Oct 09, 2003
Posts: 9
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>
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
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.


Merrill
Consultant, Sima Solutions
 
jQuery in Action, 2nd edition
 
subject: Struts html:select error