Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Variable name not rendering its value in JSP

Status
Not open for further replies.

Spab23

Programmer
Jul 22, 2003
43
CA
Hey there.

I have a web app that uses JSP/struts to render some HTML. My problem is in the html:link tag. In every other instance on my JSP page, the variables (i.e. <%=variable_name%> render into their respective values when the HTML is output to the screen. In the "onmouseover" parameter, it is not.

This is the JSP code I am working with:
Code:
<logic:iterate id="item" name="menuitems" type="org.apache.struts.tiles.beans.MenuItem">
<%	//	add site URL if the link starts with "/"
   String link = item.getLink();
   if ("".equals(link)) {%>
   <tr>
      <td colspan="2">&nbsp;</td>
   </tr>
<% }
  else if ("-".equals(link)) {%>
   <tr>
      <td colspan="2"><hr /></td>
   </tr>
<% }
   else {
%>
   <tr>
   <td  align="center">
      <img src="<%=contextPath%>/images/spacer.gif" width="12" height="12">
   </td>
   <td>
   <%
      String tooltip = "'"+item.getTooltip()+"'";
   %>
      <html:link styleClass="navLink" 
            onmouseover="showtip(this,event,<%=tooltip%>)"
            onmouseout="hidetip()"
            page="<%=link%>">
         <%=item.getValue()%>
      </html:link>
   </td>
   </tr>
<% }%>
</logic:iterate>

When the HTML renders, the <%=tooltip%> is visible in the source instead of the String value it contains. The <%=link%> and <%=item.getValue()%> variables render to their correct values, but not <%=tooltip%>. I added a line to just output the value of <%=tooltip%> to the screen (i.e. tooltip = [<%=tooltip%>]) and that works fine. The problem only exists within that "onmouseover" parameter.

Anyone have any ideas why this is happening? Does the "onmouseover" parameter escape everything inside the quotes and turn off the JSP render engine?

THanks for any suggestions you have!
 

<%
//change to this
String tooltip = item.getTooltip()+"";
%>
 
That didn't work. The variable name <%=tooltip%> is still appearing in the HTML.

D'oh!!
 
replace
onmouseover="showtip(this,event,<%=tooltip%>)"
to
onmouseover="showtip(this,event,<%=item.getTooltip()+""%>)
 
Again... the <%=item.getTooltip()+""%> appears in the HTML.

The problem is not the syntax of the variable name or method call, it's the fact that the variable name is not being rendered in the JSP engine for the "onmouseover" parameter.
 
What happens if you just try to render <%=item.getTooltip()%>?

 
If I do it outside of the "onmouseover" parameter, it works fine and renders into its appropriate value.

I even tried putting "<%=item.getTooltip()%>" or "<%=tooltip%>" inside the "page" parameter in the "html:link" tag, and that worked as well.

The only place where the variable name makes it through to the rendered HTML is in that damn "onmouseover" parameter!
 
<%
String tooltip = "showtip(this,event,"+item.getTooltip()"+")";
%>

onmouseover="<%=tooltip%>
 
// fix double quote
<%
String tooltip = "showtip(this,event,"+item.getTooltip()+")";
%>

onmouseover="<%=tooltip%>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top