struts-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Pierre Métras <gen...@sympatico.ca>
Subject Patch for Bug Report #179
Date Sat, 11 Nov 2000 01:17:16 GMT
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



Mime
View raw message