Search code examples
jspattributescommentsjsp-tags

Outcomment attribute of a JSP tag


We come across change requests with our application frequently and would like to simply comment functionality out at times in case the request is reversed.

Using JSP tags to create form elements, we use self closing tags in most cases like:

<form:radiobutton path="element_radio"  value="not known"
    onclick="return hidePanel($(this).attr('name'));"/>

of which I'd like to simply comment the onlick attribute like so:

<form:radiobutton path="element_radio"  value="not known"  
    <%--onclick="return hidePanel($(this).attr('name'));" --%>/>

Using grep, I'd normally just surround this with commenting symbols <!-- -->, <%-- --%>, etc however it appears the parser won't accept these within the tag giving an Unterminated &lt;form:radiobutton tag error.

Short of extracting these from the tag and placing them in comments at the end of the line, is there a way to do this on individual attributes?


Solution

  • After some research and discovering many similar but unanswered questions regarding the creation comments within a JSTL or JSP tag, I've found that this is simply not possible as of this writing.

    Adding elementary commenting practices so as not to skimp on details:

    While there may be some merit to retaining old code to ease reversion, this might be equated to code smell if kept within the tag. Using Java code to highlight the point, should someone in the normal course of development write a statement

     object.addObject("errMsg", "Your request could not be completed because of an error during
     processing.");
    

    updated to:

     object.addObject("errMsg" /*, "Your request could not be completed because of an error
     during processing."*/);
    

    The statement becomes harder to discern given a simple editor, but cluttered regardless.

     object.addObject("errMsg"); //, "Your request could not be completed because of an error during processing."
    

    Another approach might be to simply comment out the line entirely, creating a new with just the code needed:

    //object.addObject("errMsg", "Your request could not be completed because of an error during processing.");
     object.addObject("errMsg");
    

    All the while, each have their own approach, with some citing that source control is the best place for old code, entirely.

    So while I attempted to perform <form:radiobutton path="element_radio" value="not known" <%--onclick="return hidePanel($(this).attr('name'));" --%>/>, the point is really moot, as it's bad form and may (as well as those after or working with me) have been better served by

    <%--form:radiobutton path="element_radio"  value="not known" onclick="return hidePanel($(this).attr('name'));"/--%>
    <form:radiobutton path="element_radio"  value="not known" />