This is an automated email from the ASF dual-hosted git repository.

bitstorm pushed a commit to branch WICKET-7191
in repository https://gitbox.apache.org/repos/asf/wicket.git

commit 2975be95bdb65bc1288624360a7abb7b7613cc2b
Author: Andrea Del Bene <[email protected]>
AuthorDate: Sun Aug 16 21:23:15 2026 +0200

    WICKET-7191 Apply tag attribute "required" when a component is set to
    required
---
 .../ajax/form/AjaxFormSubmitTestPage_expected.html     |  4 ++--
 .../html/form/validation/HomePage1_ExpectedResult.html |  2 +-
 .../apache/wicket/markup/html/form/FormComponent.java  | 18 ++++++++++++++++++
 3 files changed, 21 insertions(+), 3 deletions(-)

diff --git 
a/wicket-core-tests/src/test/java/org/apache/wicket/ajax/form/AjaxFormSubmitTestPage_expected.html
 
b/wicket-core-tests/src/test/java/org/apache/wicket/ajax/form/AjaxFormSubmitTestPage_expected.html
index fcf45b76b2..b3a6346bc0 100644
--- 
a/wicket-core-tests/src/test/java/org/apache/wicket/ajax/form/AjaxFormSubmitTestPage_expected.html
+++ 
b/wicket-core-tests/src/test/java/org/apache/wicket/ajax/form/AjaxFormSubmitTestPage_expected.html
@@ -21,8 +21,8 @@ Wicket.Event.publish(Wicket.Event.Topic.AJAX_HANDLERS_BOUND);
 </script>
 </head><body>
                <form wicket:id="form" id="form1" method="post" 
action="./page?0-1.-form"><div id="form1_hf_0" hidden="" 
class="hidden-fields"></div>
-                       <input type="text" wicket:id="txt1" value="foo" 
name="txt1"/>
-                       <input type="text" wicket:id="txt2" value="bar" 
name="txt2"/>
+                       <input type="text" wicket:id="txt1" value="foo" 
name="txt1" required="required"/>
+                       <input type="text" wicket:id="txt2" value="bar" 
name="txt2" required="required"/>
                        <input type="submit" value="Submit" wicket:id="submit" 
name="p::submit" id="submit2"/>
                </form> 
        </body>
diff --git 
a/wicket-core-tests/src/test/java/org/apache/wicket/markup/html/form/validation/HomePage1_ExpectedResult.html
 
b/wicket-core-tests/src/test/java/org/apache/wicket/markup/html/form/validation/HomePage1_ExpectedResult.html
index a87014e30b..3720db5f5a 100644
--- 
a/wicket-core-tests/src/test/java/org/apache/wicket/markup/html/form/validation/HomePage1_ExpectedResult.html
+++ 
b/wicket-core-tests/src/test/java/org/apache/wicket/markup/html/form/validation/HomePage1_ExpectedResult.html
@@ -11,7 +11,7 @@
        <form wicket:id="form" id="form9" method="post" 
action="./org.apache.wicket.markup.html.form.validation.HomePage1?1-1.-bug-form"><div
 id="form9_hf_0" hidden="" class="hidden-fields"></div>
          <div wicket:id="border"><wicket:border>
                <wicket:body>
-           <input wicket:id="name" value="" name="border:border_body:name"/>
+           <input wicket:id="name" value="" name="border:border_body:name" 
required="required"/>
            <div wicket:id="feedback"><wicket:panel>
   
 </wicket:panel></div>
diff --git 
a/wicket-core/src/main/java/org/apache/wicket/markup/html/form/FormComponent.java
 
b/wicket-core/src/main/java/org/apache/wicket/markup/html/form/FormComponent.java
index 28331766df..eb7da9cb35 100644
--- 
a/wicket-core/src/main/java/org/apache/wicket/markup/html/form/FormComponent.java
+++ 
b/wicket-core/src/main/java/org/apache/wicket/markup/html/form/FormComponent.java
@@ -1409,6 +1409,11 @@ public abstract class FormComponent<T> extends 
LabeledWebMarkupContainer impleme
                        onDisabled(tag);
                }
 
+               if (isRequired())
+               {
+                       onRequired(tag);
+               }
+
                super.onComponentTag(tag);
        }
 
@@ -1424,6 +1429,19 @@ public abstract class FormComponent<T> extends 
LabeledWebMarkupContainer impleme
                convertedInput = null;
        }
 
+       /**
+        * Called by {@link #onComponentTag(ComponentTag)} when the component 
is required. By default,
+        * this method will add a required="required" attribute to the tag. 
Components may override this
+        * method to tweak the tag as they think is fit.
+        * 
+        * @param tag
+        *            the tag that is being rendered
+        */
+       protected void onRequired(final ComponentTag tag)
+       {
+               tag.put("required", "required");
+       }
+
        /**
         * Called by {@link #onComponentTag(ComponentTag)} when the component 
is disabled. By default,
         * this method will add a disabled="disabled" attribute to the tag. 
Components may override this

Reply via email to