Uploaded image for project: 'Struts 2'
  1. Struts 2
  2. WW-3920

AnchorHandler does not render onclick() correctly

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 2.3.4.1
    • 2.3.12
    • None

    Description

      The sripting methods are ignored on the <a/> tag.

      It never calls the start on ScriptingEventsHandler so does not add the attributes.

      Have checked it with image href links, which is what I think was the reason it was done this way.

      public class AnchorHandler extends AbstractTagHandler implements TagGenerator {
          public void generate() throws IOException {
              //all rendering must happend at the end of the tag, so we can support nested params
      
      // Added start
      
          	Map<String, Object> params = context.getParameters();
      
              Attributes attrs = new Attributes();
      
              attrs.addIfExists("name", params.get("name"))
                      .addIfExists("id", params.get("id"))
                      .addIfExists("class", params.get("cssClass"))
                      .addIfExists("style", params.get("cssStyle"))
                      .addIfExists("href", params.get("href"), false)
                      .addIfExists("title", params.get("title"))
                      .addIfExists("tabindex", params.get("tabindex"));
              start("a", attrs);
      
      // added end
      
          }
      
          public static class CloseHandler extends AbstractTagHandler implements TagGenerator {
              public void generate() throws IOException {
                  Map<String, Object> params = context.getParameters();
      
      // Removed
                  /*Attributes attrs = new Attributes();
      
                  attrs.addIfExists("name", params.get("name"))
                          .addIfExists("id", params.get("id"))
                          .addIfExists("class", params.get("cssClass"))
                          .addIfExists("style", params.get("cssStyle"))
                          .addIfExists("href", params.get("href"), false)
                          .addIfExists("title", params.get("title"))
                          .addIfExists("tabindex", params.get("tabindex"));
                  start("a", attrs);*/
      // removed
      
                  String body = (String) params.get("body");
                  if (StringUtils.isNotEmpty(body))
                      characters(body, false);
                  end("a");
              }
          }
      

      Attachments

        1. patch.txt
          8 kB
          Greg Huber

        Issue Links

          Activity

            ghuber Greg Huber added a comment -

            patch

            ghuber Greg Huber added a comment - patch
            ghuber Greg Huber added a comment -

            If you check the unit tests, you can see that its not checking the ScriptingEventsHandler attributes:

            ScriptingEventsHandler

            a.addIfExists("onclick", params.get("onclick"));
                    a.addIfExists("ondblclick", params.get("ondblclick"));
                    a.addIfExists("onmousedown", params.get("onmousedown"));
                    a.addIfExists("onmouseup", params.get("onmouseup"));
                    a.addIfExists("onmouseover", params.get("onmouseover"));
                    a.addIfExists("onmousemove", params.get("onmousemove"));
                    a.addIfExists("onmouseout", params.get("onmouseout"));
                    a.addIfExists("onfocus", params.get("onfocus"));
                    a.addIfExists("onblur", params.get("onblur"));
                    a.addIfExists("onkeypress", params.get("onkeypress"));
                    a.addIfExists("onkeydown", params.get("onkeydown"));
                    a.addIfExists("onkeyup", params.get("onkeyup"));
                    a.addIfExists("onselect", params.get("onselect"));
                    a.addIfExists("onchange", params.get("onchange"));
            
            

            AnchorTest, not testing for above attributes.

            tag.setName("name_");
                    tag.setDisabled("true");
                    tag.setTabindex("1");
                    tag.setId("id_");
                    tag.setCssClass("class");
                    tag.setCssStyle("style");
                    tag.setTitle("title");
                    tag.setHref("http://sometest.com?ab=10");
            
            
            ghuber Greg Huber added a comment - If you check the unit tests, you can see that its not checking the ScriptingEventsHandler attributes: ScriptingEventsHandler a.addIfExists( "onclick" , params.get( "onclick" )); a.addIfExists( "ondblclick" , params.get( "ondblclick" )); a.addIfExists( "onmousedown" , params.get( "onmousedown" )); a.addIfExists( "onmouseup" , params.get( "onmouseup" )); a.addIfExists( "onmouseover" , params.get( "onmouseover" )); a.addIfExists( "onmousemove" , params.get( "onmousemove" )); a.addIfExists( "onmouseout" , params.get( "onmouseout" )); a.addIfExists( "onfocus" , params.get( "onfocus" )); a.addIfExists( "onblur" , params.get( "onblur" )); a.addIfExists( "onkeypress" , params.get( "onkeypress" )); a.addIfExists( "onkeydown" , params.get( "onkeydown" )); a.addIfExists( "onkeyup" , params.get( "onkeyup" )); a.addIfExists( "onselect" , params.get( "onselect" )); a.addIfExists( "onchange" , params.get( "onchange" )); AnchorTest, not testing for above attributes. tag.setName( "name_" ); tag.setDisabled( " true " ); tag.setTabindex( "1" ); tag.setId( "id_" ); tag.setCssClass( "class" ); tag.setCssStyle( "style" ); tag.setTitle( "title" ); tag.setHref( "http: //sometest.com?ab=10" );
            lukaszlenart Lukasz Lenart added a comment -

            gregh99 but the attached patch is not related to issue you described.

            lukaszlenart Lukasz Lenart added a comment - gregh99 but the attached patch is not related to issue you described.
            lukaszlenart Lukasz Lenart added a comment -

            I think, the patch is related to WW-3922

            lukaszlenart Lukasz Lenart added a comment - I think, the patch is related to WW-3922
            lukaszlenart Lukasz Lenart added a comment -

            Patch applied, thanks for reporting!

            lukaszlenart Lukasz Lenart added a comment - Patch applied, thanks for reporting!
            hudson Hudson added a comment -

            Integrated in Struts2-JDK6 #623 (See https://builds.apache.org/job/Struts2-JDK6/623/)
            WW-3920 adds support for scripting events (Revision 1436637)

            Result = SUCCESS
            lukaszlenart :
            Files :

            • /struts/struts2/trunk/plugins/javatemplates/src/main/java/org/apache/struts2/views/java/simple/AnchorHandler.java
            • /struts/struts2/trunk/plugins/javatemplates/src/test/java/org/apache/struts2/views/java/simple/AnchorTest.java
            hudson Hudson added a comment - Integrated in Struts2-JDK6 #623 (See https://builds.apache.org/job/Struts2-JDK6/623/ ) WW-3920 adds support for scripting events (Revision 1436637) Result = SUCCESS lukaszlenart : Files : /struts/struts2/trunk/plugins/javatemplates/src/main/java/org/apache/struts2/views/java/simple/AnchorHandler.java /struts/struts2/trunk/plugins/javatemplates/src/test/java/org/apache/struts2/views/java/simple/AnchorTest.java
            hudson Hudson added a comment -

            Integrated in Struts2-JDK6 #720 (See https://builds.apache.org/job/Struts2-JDK6/720/)
            WW-4084 Restores appending <s:param>s to <s:a/> tag which was broken since WW-3920 (Revision 1487806)

            Result = SUCCESS
            lukaszlenart :
            Files :

            • /struts/struts2/trunk/plugins/javatemplates/src/main/java/org/apache/struts2/views/java/simple/AnchorHandler.java
            • /struts/struts2/trunk/plugins/javatemplates/src/main/java/org/apache/struts2/views/java/simple/SimpleTheme.java
            hudson Hudson added a comment - Integrated in Struts2-JDK6 #720 (See https://builds.apache.org/job/Struts2-JDK6/720/ ) WW-4084 Restores appending <s:param>s to <s:a/> tag which was broken since WW-3920 (Revision 1487806) Result = SUCCESS lukaszlenart : Files : /struts/struts2/trunk/plugins/javatemplates/src/main/java/org/apache/struts2/views/java/simple/AnchorHandler.java /struts/struts2/trunk/plugins/javatemplates/src/main/java/org/apache/struts2/views/java/simple/SimpleTheme.java
            ghuber Greg Huber added a comment -

            OK, sorry should have read the comment and checked it worked with parameters!

            //all rendering must happend at the end of the tag, so we can support nested params

            Tend not to use parameters in the body as will get parameters with empty values ie ?foo= for null values. btw is there a way to filter these out? similar to the struts.xml <param name="suppressEmptyParameters">true</param>. The <s:if> tags in the body are ignored.

            ie possibly do something similar :

            <s:a action="eventAdd" accesskey="a">
            <s:text name="title.heading.eventadd" />
            <s:param name="bean.searchString" value="%

            {bean.searchString}

            " />
            <s:param name="bean.filter" value="%

            {bean.filter}

            " />
            <s:param name="bean.pageNum" value="%

            {pager.pageNumber}

            " />
            <s:param name="suppressEmptyParameters" value="true"/> <<<<<<<<<<<<<<< ????
            </s:a>

            It also now works with the scriting tags.

            Cheers Greg

            ghuber Greg Huber added a comment - OK, sorry should have read the comment and checked it worked with parameters! //all rendering must happend at the end of the tag, so we can support nested params Tend not to use parameters in the body as will get parameters with empty values ie ?foo= for null values. btw is there a way to filter these out? similar to the struts.xml <param name="suppressEmptyParameters">true</param>. The <s:if> tags in the body are ignored. ie possibly do something similar : <s:a action="eventAdd" accesskey="a"> <s:text name="title.heading.eventadd" /> <s:param name="bean.searchString" value="% {bean.searchString} " /> <s:param name="bean.filter" value="% {bean.filter} " /> <s:param name="bean.pageNum" value="% {pager.pageNumber} " /> <s:param name="suppressEmptyParameters" value="true"/> <<<<<<<<<<<<<<< ???? </s:a> It also now works with the scriting tags. Cheers Greg
            lukaszlenart Lukasz Lenart added a comment -

            gregh99 Could you wrap your comment with {{

            
            

            }} ? And please register a new issue regarding suppressEmptyParameters

            lukaszlenart Lukasz Lenart added a comment - gregh99 Could you wrap your comment with {{ }} ? And please register a new issue regarding suppressEmptyParameters
            lukaszlenart Lukasz Lenart added a comment -

            {code:xml}

            lukaszlenart Lukasz Lenart added a comment - {code:xml}
            ghuber Greg Huber added a comment -

            Did try to add them but could not edit the comment. See WW-4088. Will see if I can do a patch (that works!).

            Cheers Greg.

            ghuber Greg Huber added a comment - Did try to add them but could not edit the comment. See WW-4088 . Will see if I can do a patch (that works!). Cheers Greg.

            People

              lukaszlenart Lukasz Lenart
              ghuber Greg Huber
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: