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

About html:link

 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I do like this:
<html:link href="javascript penScript('display.jsp?id=<bean:write name="mybean" property="id" />');">my link</html:link>
It's error!
Exception rg.apache.jasper.JasperException: /myCode.jsp(24,157) equal symbol expected
How am I do with "<html:link" and "<bean:write" but like following???
<a href="javascript penScript('display.jsp?id=<bean:write name="mybean" property="id" />');">my link</a>
 
author
Posts: 184
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Xi,
It is not the problem of having included JavaScript, but having included a custom tag within the XML node of a custom tag - which is illegal.
<html:link href="javascriptOpenScript('display.jsp?id=<bean:write name="mybean" property="id" />');">my link</html:link>
It's error!
If you really want to use the Struts tags, then you have to use the Struts-EL tags instead of normal Struts Tags. With Struts-EL, the above tag is rewritten as follows:
<html-el:link href="javascriptOpenScript('display.jsp?id=${mybean.id}');">my link</html-el:link>
Be sure to include jstl.jar, standard.jar (remember to use the Jakarta Taglibs version, not the Sun reference implementation jar), struts-el.jar in your web application classpath. These jars are needed in addition to the already existing jars from regular Struts.
The above tag uses the JSTL Expression language to simplify the tag.
Some more explanation about the Expression language is in order. Here goes:
Any value to be evaluated in a JSTL tag lies in ${ and } blocks. EL defines
several implicit objects much like JSP defines its implicit objects. If the name of the variable in the ${ and } block does not match one of the implicit objects (in this case it does not), then EL searches the page, request, session application scopes in that order for the variable name specified. In the above code snippet, �mybean� is the name of an attribute in one of these scopes. id is a JavaBean property in the bean, mybean.
Hope this helps.
Srikanth Shenoy
Author: Struts Survival Guide - Basics to Best Practices
ObjectSource Publications
[ February 20, 2004: Message edited by: Srikanth Shenoy ]
 
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Srikanth is correct. Placing a struts tag within an attribute of another struts tag is a definite no-no. But there are a number of ways to get around it.
My favorite method is to save the entire attribute value as a String variable and then insert it as an expression.
<%
String scriptString = "javascript...." + getMyValue() + "...";
%>
<html:link href="<%= scriptString %>">my link</html:link>
 
xi ruo
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


<%
String scriptString = "javascript...." + getMyValue() + "...";
%>
<html:link href="<%= scriptString %>">my link</html:link>


It's matter by my trying,Convert to HTML code following:
<a href="<%=scriptString%>">my link</a>
Srikanth Shenoy:
Thanks for for your suggestion!
 
reply
    Bookmark Topic Watch Topic
  • New Topic