You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by Pierre Métras <ge...@sympatico.ca> on 2000/11/11 02:17:16 UTC
Patch for Bug Report #179
Hi all,
As I was making some cleaning in my code, I decided to file that feature and
propose it before version 1.0
http://znutar.cortexity.com:8888/BugRatViewer/ShowReport/179
Synopsis:
LinkTag should support MouseEvents as in HTML4.0
Description:
The LinkTag should be derived from BaseHandlerTag
instead of TagSupport since HTML allows JS on mouse-events for HREFs
The patch I send below adds support for JavaScript events. It also adds a
new property "linkName" that allows to give a name to the resulting <a>
link.
Here is an extract of code using the new attributes, from a graphical menu
with a rollover effect:
<struts:link href="menu.do?action=Mosaic"
onMouseOver="rollOver('mosaic', true);" onMouseOut="rollOver('mosaic',
false);" styleClass="menu">
<img name="mosaic" src="img/butMosaicOff.gif" border="0"
alt="<s:message key="menu.option.mosaic.alt" />" width="58" height="58">
</s:link>
Well, my editor likes to play with tabs and white spaces, so I am unable to
send a patch file. But as the modifications are quite minor, let's start for
a manual patch.
*** Main modifications occur in LinkTag.java file, Revision 1.11 dated
2000/08/14 (I presume Link1 will be dead by version 1.0?).
+ Change the inheritance clause to extend from BaseHandlerTag instead of
TagSupport.
---- Start ----
public class LinkTag extends BaseHandlerTag {
---- End ----
- So you can remove import for TagSupport
---- Start ----
import javax.servlet.jsp.tagext.TagSupport;
---- End ----
+ Add the linkName property to allow to name links (as "name" is already
used):
---- Start ----
/**
* The link name in the resulting HTML.
*/
protected String linkName = null;
---- End ----
+ Add also the getter and setter functions:
---- Start ----
/**
* Return the name of the HTML link.
*
* @return The name of the link.
*/
public String getLinkName() {
return this.linkName;
}
/**
* Set the HTML link name.
*
* @param linkName The name of the resulting link.
*/
public void setLinkName(String linkName) {
this.linkName = linkName;
}
---- End ----
+ Change doStartTag() to take into account the new properties
---- Start ----
if (target != null) {
results.append(" target=\"");
results.append(target);
results.append("\"");
}
// FROM HERE ...
if (linkName != null) {
results.append(" name=\"");
results.append(linkName);
results.append("\"");
}
results.append(prepareStyles());
results.append(prepareEventHandlers());
// ... TO HERE
results.append(">");
---- End ----
+ Also now that LinkTag inherits from BodyTagSupport, it's not allowed
anymore to return a EVAL_BODY_INCLUDE. Change it to an EVAL_BODY_TAG.
---- Start ----
// Evaluate the body of this tag
return (EVAL_BODY_TAG);
}
--- End ----
+ Adapt doEndTag() to write tag body now that we don't include body...
---- Start ----
// Print the ending element to our output writer
JspWriter writer = pageContext.getOut();
try {
// NEW FROM HERE...
if (bodyContent != null) {
writer.println(bodyContent.getString().trim());
}
// ... TO THERE
writer.print("</a>");
} catch (IOException e) {
throw new JspException
(messages.getMessage("common.io", e.toString()));
}
--- End ----
+ Take into account the new field for clean up, in realease() add:
---- Start ----
linkName = null;
--- End ----
*** Now change struts.tld to add the new attributes. Here I give the whole
definition, including the attributes given by BaseHandler:
---- Start ----
<tag>
<name>link</name>
<tagclass>org.apache.struts.taglib.LinkTag</tagclass>
<bodycontent>JSP</bodycontent>
<attribute>
<name>forward</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>href</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>name</name>
<required>false</required>
<rtexprvalue>false</rtexprvalue>
</attribute>
<attribute>
<name>property</name>
<required>false</required>
<rtexprvalue>false</rtexprvalue>
</attribute>
<attribute>
<name>target</name>
<required>false</required>
<rtexprvalue>false</rtexprvalue>
</attribute>
<attribute>
<name>linkName</name>
<required>false</required>
<rtexprvalue>false</rtexprvalue>
</attribute>
<attribute>
<name>accessKey</name>
<required>false</required>
<rtexprvalue>false</rtexprvalue>
</attribute>
<attribute>
<name>tabIndex</name>
<required>false</required>
<rtexprvalue>false</rtexprvalue>
</attribute>
<attribute>
<name>onClick</name>
<required>false</required>
<rtexprvalue>false</rtexprvalue>
</attribute>
<attribute>
<name>onDblClick</name>
<required>false</required>
<rtexprvalue>false</rtexprvalue>
</attribute>
<attribute>
<name>onMouseOver</name>
<required>false</required>
<rtexprvalue>false</rtexprvalue>
</attribute>
<attribute>
<name>onMouseOut</name>
<required>false</required>
<rtexprvalue>false</rtexprvalue>
</attribute>
<attribute>
<name>onMouseMove</name>
<required>false</required>
<rtexprvalue>false</rtexprvalue>
</attribute>
<attribute>
<name>onMouseDown</name>
<required>false</required>
<rtexprvalue>false</rtexprvalue>
</attribute>
<attribute>
<name>onMouseUp</name>
<required>false</required>
<rtexprvalue>false</rtexprvalue>
</attribute>
<attribute>
<name>onKeyDown</name>
<required>false</required>
<rtexprvalue>false</rtexprvalue>
</attribute>
<attribute>
<name>onKeyUp</name>
<required>false</required>
<rtexprvalue>false</rtexprvalue>
</attribute>
<attribute>
<name>onKeyPress</name>
<required>false</required>
<rtexprvalue>false</rtexprvalue>
</attribute>
<attribute>
<name>onSelect</name>
<required>false</required>
<rtexprvalue>false</rtexprvalue>
</attribute>
<attribute>
<name>onChange</name>
<required>false</required>
<rtexprvalue>false</rtexprvalue>
</attribute>
<attribute>
<name>onBlur</name>
<required>false</required>
<rtexprvalue>false</rtexprvalue>
</attribute>
<attribute>
<name>onFocus</name>
<required>false</required>
<rtexprvalue>false</rtexprvalue>
</attribute>
<attribute>
<name>style</name>
<required>false</required>
<rtexprvalue>false</rtexprvalue>
</attribute>
<attribute>
<name>styleClass</name>
<required>false</required>
<rtexprvalue>false</rtexprvalue>
</attribute>
</tag>
--- End ----
That's all folks!
Pierre Métras
Re: Patch for Bug Report #179
Posted by Oleg V Alexeev <go...@penza.net>.
Hello Pierre,
Great! Thank you.
Saturday, November 11, 2000, 4:17:16 AM, you wrote:
PM> Hi all,
PM> As I was making some cleaning in my code, I decided to file that feature and
PM> propose it before version 1.0
> ....
--
Best regards,
Oleg mailto:gonza@penza.net
Re: Patch for Bug Report #179
Posted by Pierre Métras <ge...@sympatico.ca>.
Just forgot to say that according to HTML 4.0, <a> tag supports a few other
attributes (title, id, lang...), but they would better go into
BaseHandlerTag class, and some specifi ones (accesskey, coords, shape...).
Next time will be better.
Pierre Métras