Struts 2
  1. Struts 2
  2. WW-3908

FreeMarker textfield tag doesn't allow the new HTML5 required attribute

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.3.7
    • Fix Version/s: 2.3.12
    • Component/s: None
    • Labels:
      None
    • Environment:

      Windows 7 + JDK1.6.0_27 + The new Struts2 2.3.6 + FreeMarker 2.3.19

    • Flags:
      Important

      Description

      It is impossible to use the new HTML5 required attribute with the textfield tag currently available in FreeMarker. Other HTML5 attributes seem to work as expected.

      => For example, I want to use the new required attribute in order to have the following very simple HTML code :

      <input type="text" required="required" id="test-X">
      

      => I have tried to use the following code in a classic FTL file :

      test.ftl
      <@s.textfield required="required" id="test-1"/>
      <@s.textfield required="true" id="test-2"/>
      <@s.textfield required=required id="test-3"/>
      <@s.textfield required=true id="test-4"/>
      

      The HTML result is always :

      <input type="text" id="test-X">
      

        Issue Links

          Activity

          Hide
          Jose L Martinez-Avial added a comment -

          I believe that the reason for that is that required is an attribute defined in the TLD, so it is not treated as a dynamic attribute, like other HTML5. I think the tag uses that attribute for client-side validations, but if client-side validation is not used, then the tag does not pass the attribute to the tag, like it does with the dynamic attributes. I have the same problem.

          Show
          Jose L Martinez-Avial added a comment - I believe that the reason for that is that required is an attribute defined in the TLD, so it is not treated as a dynamic attribute, like other HTML5. I think the tag uses that attribute for client-side validations, but if client-side validation is not used, then the tag does not pass the attribute to the tag, like it does with the dynamic attributes. I have the same problem.
          Hide
          Lukasz Lenart added a comment -

          The problem is a bit different - there is already attribute "required" but used to display "*" next to the label to mark field as required

          I think it should be renamed to requiredLabel and then support for HTML5 required attribute will available OOTB

          Show
          Lukasz Lenart added a comment - The problem is a bit different - there is already attribute "required" but used to display "*" next to the label to mark field as required I think it should be renamed to requiredLabel and then support for HTML5 required attribute will available OOTB
          Hide
          Lukasz Lenart added a comment -

          Done, required attribute renamed to requiredLabel. Could you test with the latest snapshot build?

          Show
          Lukasz Lenart added a comment - Done, required attribute renamed to requiredLabel. Could you test with the latest snapshot build?
          Hide
          Hudson added a comment -

          Integrated in Struts2-JDK6 #617 (See https://builds.apache.org/job/Struts2-JDK6/617/)
          WW-3908 renames required attribute into requiredLabel to allow support of Html5 required attribute (Revision 1434580)

          Result = SUCCESS
          lukaszlenart :
          Files :

          • /struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/UIBean.java
          • /struts/struts2/trunk/core/src/main/java/org/apache/struts2/views/jsp/ui/AbstractUITag.java
          • /struts/struts2/trunk/core/src/site/resources/tags/a.html
          • /struts/struts2/trunk/core/src/site/resources/tags/actionerror.html
          • /struts/struts2/trunk/core/src/site/resources/tags/actionmessage.html
          • /struts/struts2/trunk/core/src/site/resources/tags/ajax/a.html
          • /struts/struts2/trunk/core/src/site/resources/tags/ajax/autocompleter.html
          • /struts/struts2/trunk/core/src/site/resources/tags/ajax/datetimepicker.html
          • /struts/struts2/trunk/core/src/site/resources/tags/ajax/div.html
          • /struts/struts2/trunk/core/src/site/resources/tags/ajax/submit.html
          • /struts/struts2/trunk/core/src/site/resources/tags/ajax/tabbedpanel.html
          • /struts/struts2/trunk/core/src/site/resources/tags/ajax/textarea.html
          • /struts/struts2/trunk/core/src/site/resources/tags/ajax/tree.html
          • /struts/struts2/trunk/core/src/site/resources/tags/ajax/treenode.html
          • /struts/struts2/trunk/core/src/site/resources/tags/checkbox.html
          • /struts/struts2/trunk/core/src/site/resources/tags/checkboxlist.html
          • /struts/struts2/trunk/core/src/site/resources/tags/combobox.html
          • /struts/struts2/trunk/core/src/site/resources/tags/component.html
          • /struts/struts2/trunk/core/src/site/resources/tags/debug.html
          • /struts/struts2/trunk/core/src/site/resources/tags/div.html
          • /struts/struts2/trunk/core/src/site/resources/tags/doubleselect.html
          • /struts/struts2/trunk/core/src/site/resources/tags/fielderror.html
          • /struts/struts2/trunk/core/src/site/resources/tags/file.html
          • /struts/struts2/trunk/core/src/site/resources/tags/form.html
          • /struts/struts2/trunk/core/src/site/resources/tags/head.html
          • /struts/struts2/trunk/core/src/site/resources/tags/hidden.html
          • /struts/struts2/trunk/core/src/site/resources/tags/inputtransferselect.html
          • /struts/struts2/trunk/core/src/site/resources/tags/label.html
          • /struts/struts2/trunk/core/src/site/resources/tags/optiontransferselect.html
          • /struts/struts2/trunk/core/src/site/resources/tags/password.html
          • /struts/struts2/trunk/core/src/site/resources/tags/radio.html
          • /struts/struts2/trunk/core/src/site/resources/tags/reset.html
          • /struts/struts2/trunk/core/src/site/resources/tags/select.html
          • /struts/struts2/trunk/core/src/site/resources/tags/submit.html
          • /struts/struts2/trunk/core/src/site/resources/tags/textarea.html
          • /struts/struts2/trunk/core/src/site/resources/tags/textfield.html
          • /struts/struts2/trunk/core/src/site/resources/tags/token.html
          • /struts/struts2/trunk/core/src/site/resources/tags/updownselect.html
          • /struts/struts2/trunk/core/src/test/java/org/apache/struts2/views/freemarker/FreeMarkerResultTest.java
          • /struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/freemarker/dynaAttributes.ftl
          Show
          Hudson added a comment - Integrated in Struts2-JDK6 #617 (See https://builds.apache.org/job/Struts2-JDK6/617/ ) WW-3908 renames required attribute into requiredLabel to allow support of Html5 required attribute (Revision 1434580) Result = SUCCESS lukaszlenart : Files : /struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/UIBean.java /struts/struts2/trunk/core/src/main/java/org/apache/struts2/views/jsp/ui/AbstractUITag.java /struts/struts2/trunk/core/src/site/resources/tags/a.html /struts/struts2/trunk/core/src/site/resources/tags/actionerror.html /struts/struts2/trunk/core/src/site/resources/tags/actionmessage.html /struts/struts2/trunk/core/src/site/resources/tags/ajax/a.html /struts/struts2/trunk/core/src/site/resources/tags/ajax/autocompleter.html /struts/struts2/trunk/core/src/site/resources/tags/ajax/datetimepicker.html /struts/struts2/trunk/core/src/site/resources/tags/ajax/div.html /struts/struts2/trunk/core/src/site/resources/tags/ajax/submit.html /struts/struts2/trunk/core/src/site/resources/tags/ajax/tabbedpanel.html /struts/struts2/trunk/core/src/site/resources/tags/ajax/textarea.html /struts/struts2/trunk/core/src/site/resources/tags/ajax/tree.html /struts/struts2/trunk/core/src/site/resources/tags/ajax/treenode.html /struts/struts2/trunk/core/src/site/resources/tags/checkbox.html /struts/struts2/trunk/core/src/site/resources/tags/checkboxlist.html /struts/struts2/trunk/core/src/site/resources/tags/combobox.html /struts/struts2/trunk/core/src/site/resources/tags/component.html /struts/struts2/trunk/core/src/site/resources/tags/debug.html /struts/struts2/trunk/core/src/site/resources/tags/div.html /struts/struts2/trunk/core/src/site/resources/tags/doubleselect.html /struts/struts2/trunk/core/src/site/resources/tags/fielderror.html /struts/struts2/trunk/core/src/site/resources/tags/file.html /struts/struts2/trunk/core/src/site/resources/tags/form.html /struts/struts2/trunk/core/src/site/resources/tags/head.html /struts/struts2/trunk/core/src/site/resources/tags/hidden.html /struts/struts2/trunk/core/src/site/resources/tags/inputtransferselect.html /struts/struts2/trunk/core/src/site/resources/tags/label.html /struts/struts2/trunk/core/src/site/resources/tags/optiontransferselect.html /struts/struts2/trunk/core/src/site/resources/tags/password.html /struts/struts2/trunk/core/src/site/resources/tags/radio.html /struts/struts2/trunk/core/src/site/resources/tags/reset.html /struts/struts2/trunk/core/src/site/resources/tags/select.html /struts/struts2/trunk/core/src/site/resources/tags/submit.html /struts/struts2/trunk/core/src/site/resources/tags/textarea.html /struts/struts2/trunk/core/src/site/resources/tags/textfield.html /struts/struts2/trunk/core/src/site/resources/tags/token.html /struts/struts2/trunk/core/src/site/resources/tags/updownselect.html /struts/struts2/trunk/core/src/test/java/org/apache/struts2/views/freemarker/FreeMarkerResultTest.java /struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/freemarker/dynaAttributes.ftl
          Hide
          Hudson added a comment -

          Integrated in Struts2-JDK6 #641 (See https://builds.apache.org/job/Struts2-JDK6/641/)
          WW-3908 Renames required into requiredLabel to allow support of Html5 required attribute (Revision 1442481)

          Result = SUCCESS
          lukaszlenart :
          Files :

          • /struts/struts2/trunk/core/src/main/java/org/apache/struts2/views/jsp/ui/AbstractUITag.java
          Show
          Hudson added a comment - Integrated in Struts2-JDK6 #641 (See https://builds.apache.org/job/Struts2-JDK6/641/ ) WW-3908 Renames required into requiredLabel to allow support of Html5 required attribute (Revision 1442481) Result = SUCCESS lukaszlenart : Files : /struts/struts2/trunk/core/src/main/java/org/apache/struts2/views/jsp/ui/AbstractUITag.java
          Hide
          Loic VSCT added a comment -

          Sorry for the late reply.
          I have tested with the latest snapshot today and everything seems to be OK.
          Thanks for the fix.

          Show
          Loic VSCT added a comment - Sorry for the late reply. I have tested with the latest snapshot today and everything seems to be OK. Thanks for the fix.
          Hide
          Lukasz Lenart added a comment -

          Loic VSCT did you test with 2.3.9-SNAPSHOT or with 2.3.10-SNAPSHOT? As there was a problem with requiredLabel attribute in 2.3.9 which is s showstopper for 2.3.9 (will be dropped and 2.3.10 test release will be available in few days).

          Show
          Lukasz Lenart added a comment - Loic VSCT did you test with 2.3.9-SNAPSHOT or with 2.3.10-SNAPSHOT? As there was a problem with requiredLabel attribute in 2.3.9 which is s showstopper for 2.3.9 (will be dropped and 2.3.10 test release will be available in few days).
          Hide
          Loic VSCT added a comment -

          Tested with the following code with the 2.3.9-SNAPSHOT :

          test.ftl
          <@s.textfield id="test" value="test-value" required="required" requiredLabel="true" />
          

          Not tested without the "required" attribute yet.

          Show
          Loic VSCT added a comment - Tested with the following code with the 2.3.9-SNAPSHOT : test.ftl <@s.textfield id= "test" value= "test-value" required= "required" requiredLabel= " true " /> Not tested without the "required" attribute yet.
          Hide
          Roland McIntosh added a comment -

          I wish I had noticed this issue to weigh-in.

          I don't see how keeping the attribute name as "required" precludes html5 usage – this could be handled in the tag theme, which seems like a more appropriate place to make a change for output. For example, "text.ftl" could have a section like this:

           <#if parameters.required?default(false)>
            required="required"<#rt/>
           </#if>
          
          Show
          Roland McIntosh added a comment - I wish I had noticed this issue to weigh-in. I don't see how keeping the attribute name as "required" precludes html5 usage – this could be handled in the tag theme, which seems like a more appropriate place to make a change for output. For example, "text.ftl" could have a section like this: <# if parameters.required? default ( false )> required= "required" <#rt/> </# if >
          Hide
          Lukasz Lenart added a comment -

          First we don't have such a theme and secondly thus can be simple handled via dynamicAttributes which are already in place.

          Show
          Lukasz Lenart added a comment - First we don't have such a theme and secondly thus can be simple handled via dynamicAttributes which are already in place.
          Hide
          Roland McIntosh added a comment -

          Handling via dynamicAttributes is the wrong way to do it, because the HTML5 "required" attribute is a boolean attribute – it is only ever supposed to be required="required" or missing entirely. The right-hand side (what it's equal to) doesn't matter. And the "text.ftl" file I was referring to was "simple/text.ftl", which we definitely have. Or at least css_xhtml/text.ftl.

          The problem with having it as a dynamicAttribute is that people can specify "required=false" on the struts tag. This yields "required="false"" in the output, which confusingly actually DOES require the field and breaks expectations.

          I believe that changing the themes to add "required='required'" and preserving the struts tag attribute boolean name of "required" is a better solution. In some respects this reverts to pre-2.3.12 behavior. Moving discussion to users list now.

          Show
          Roland McIntosh added a comment - Handling via dynamicAttributes is the wrong way to do it, because the HTML5 "required" attribute is a boolean attribute – it is only ever supposed to be required="required" or missing entirely. The right-hand side (what it's equal to) doesn't matter. And the "text.ftl" file I was referring to was "simple/text.ftl", which we definitely have. Or at least css_xhtml/text.ftl. The problem with having it as a dynamicAttribute is that people can specify "required=false" on the struts tag. This yields "required="false"" in the output, which confusingly actually DOES require the field and breaks expectations. I believe that changing the themes to add "required='required'" and preserving the struts tag attribute boolean name of "required" is a better solution. In some respects this reverts to pre-2.3.12 behavior. Moving discussion to users list now.
          Hide
          Lukasz Lenart added a comment -

          Roland McIntosh please jump in here WW-4188

          Show
          Lukasz Lenart added a comment - Roland McIntosh please jump in here WW-4188

            People

            • Assignee:
              Lukasz Lenart
              Reporter:
              Loic VSCT
            • Votes:
              1 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development