You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by "mira-silhavy (via GitHub)" <gi...@apache.org> on 2025/06/13 13:31:01 UTC

[PR] WICKET-7159 - Remove isEnabledInHierarchy condition from validate Form [wicket]

mira-silhavy opened a new pull request, #1186:
URL: https://github.com/apache/wicket/pull/1186

   https://issues.apache.org/jira/browse/WICKET-7159
   
   Reverting the breaking change introduced in https://github.com/apache/wicket/pull/1033#discussion_r2104060257
   
   After upgrading to Wicket 10.x, form validators (IFormValidator) are not executed if any dependent form component is disabled, due to the addition of an isEnabledInHierarchy() check. This breaks backward compatibility for applications that rely on validators with conditionally enabled/disabled fields, as the validator is now skipped in these cases. This impacts forms with cross-field validation logic and causes migration issues for existing applications. A flag or configuration to restore the previous behavior, or reverting the change, is needed for backward compatibility


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@wicket.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] WICKET-7159 - Remove isEnabledInHierarchy condition from validate Form [wicket]

Posted by "mira-silhavy (via GitHub)" <gi...@apache.org>.
mira-silhavy commented on code in PR #1186:
URL: https://github.com/apache/wicket/pull/1186#discussion_r2146915890


##########
wicket-core/src/main/java/org/apache/wicket/markup/html/form/Form.java:
##########
@@ -1986,7 +1986,7 @@ protected final void validateFormValidator(final IFormValidator validator)
 				}
 				// check if the dependent component is visible and is attached to
 				// the page
-				else if (!dependent.isVisibleInHierarchy() || !dependent.isEnabledInHierarchy() || !dependent.isFormParticipant())

Review Comment:
   I looked into the whole code and it does seem to do what you asked. The whole method looks like this
   ```
   	protected final void validateFormValidator(final IFormValidator validator)
   	{
   		Args.notNull(validator, "validator");
   
   		final FormComponent<?>[] dependents = validator.getDependentFormComponents();
   
   		boolean validate = false;
   
   		if (dependents != null)
   		{
   			for (final FormComponent<?> dependent : dependents)
   			{
   				if (dependent.isEnabledInHierarchy())
   				{
   					validate = true;
   					// check if the dependent component is valid 
   					if (!dependent.isValid())
   					{
   						validate = false;
   						break;
   					}
   					// check if the dependent component is visible and is attached to
   					// the page
   					else if (!dependent.isVisibleInHierarchy() || !dependent.isFormParticipant())
   					{
   						if (log.isWarnEnabled())
   						{
   							log.warn("IFormValidator in form `" +
   								getPageRelativePath() +
   								"` depends on a component that has been removed from the page or is no longer visible. " +
   								"Offending component id `" + dependent.getId() + "`.");
   						}
   						validate = false;
   						break;
   					}
   				}
   			}
   		}
   
   		if (validate)
   		{
   			validator.validate(this);
   		}
   	}



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@wicket.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] WICKET-7159 - Remove isEnabledInHierarchy condition from validate Form [wicket]

Posted by "mira-silhavy (via GitHub)" <gi...@apache.org>.
mira-silhavy commented on code in PR #1186:
URL: https://github.com/apache/wicket/pull/1186#discussion_r2167424604


##########
wicket-core/src/main/java/org/apache/wicket/markup/html/form/Form.java:
##########
@@ -1986,7 +1986,7 @@ protected final void validateFormValidator(final IFormValidator validator)
 				}
 				// check if the dependent component is visible and is attached to
 				// the page
-				else if (!dependent.isVisibleInHierarchy() || !dependent.isEnabledInHierarchy() || !dependent.isFormParticipant())

Review Comment:
   Thinking about the test fix I did in the last commit, what do you think of a case when `null` is being returned? Do you think it is a valid use case when a developer would want to use FormValidator without any dependent component, e.g. show error based on some condition in model data?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@wicket.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] WICKET-7159 - Remove isEnabledInHierarchy condition from validate Form [wicket]

Posted by "mira-silhavy (via GitHub)" <gi...@apache.org>.
mira-silhavy commented on code in PR #1186:
URL: https://github.com/apache/wicket/pull/1186#discussion_r2146915890


##########
wicket-core/src/main/java/org/apache/wicket/markup/html/form/Form.java:
##########
@@ -1986,7 +1986,7 @@ protected final void validateFormValidator(final IFormValidator validator)
 				}
 				// check if the dependent component is visible and is attached to
 				// the page
-				else if (!dependent.isVisibleInHierarchy() || !dependent.isEnabledInHierarchy() || !dependent.isFormParticipant())

Review Comment:
   I looked into the whole code and it already does what you asked. The whole method looks like this
   ```
   	protected final void validateFormValidator(final IFormValidator validator)
   	{
   		Args.notNull(validator, "validator");
   
   		final FormComponent<?>[] dependents = validator.getDependentFormComponents();
   
   		boolean validate = false;
   
   		if (dependents != null)
   		{
   			for (final FormComponent<?> dependent : dependents)
   			{
   				if (dependent.isEnabledInHierarchy())
   				{
   					validate = true;
   					// check if the dependent component is valid 
   					if (!dependent.isValid())
   					{
   						validate = false;
   						break;
   					}
   					// check if the dependent component is visible and is attached to
   					// the page
   					else if (!dependent.isVisibleInHierarchy() || !dependent.isFormParticipant())
   					{
   						if (log.isWarnEnabled())
   						{
   							log.warn("IFormValidator in form `" +
   								getPageRelativePath() +
   								"` depends on a component that has been removed from the page or is no longer visible. " +
   								"Offending component id `" + dependent.getId() + "`.");
   						}
   						validate = false;
   						break;
   					}
   				}
   			}
   		}
   
   		if (validate)
   		{
   			validator.validate(this);
   		}
   	}



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@wicket.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] WICKET-7159 - Remove isEnabledInHierarchy condition from validate Form [wicket]

Posted by "mira-silhavy (via GitHub)" <gi...@apache.org>.
mira-silhavy commented on code in PR #1186:
URL: https://github.com/apache/wicket/pull/1186#discussion_r2146915890


##########
wicket-core/src/main/java/org/apache/wicket/markup/html/form/Form.java:
##########
@@ -1986,7 +1986,7 @@ protected final void validateFormValidator(final IFormValidator validator)
 				}
 				// check if the dependent component is visible and is attached to
 				// the page
-				else if (!dependent.isVisibleInHierarchy() || !dependent.isEnabledInHierarchy() || !dependent.isFormParticipant())

Review Comment:
   I looked into the whole code and it already does what you asked. The whole method looks like this
   ```
   	protected final void validateFormValidator(final IFormValidator validator)
   	{
   		Args.notNull(validator, "validator");
   
   		final FormComponent<?>[] dependents = validator.getDependentFormComponents();
   
   		boolean validate = false;
   
   		if (dependents != null)
   		{
   			for (final FormComponent<?> dependent : dependents)
   			{
   				if (dependent.isEnabledInHierarchy())
   				{
   					validate = true;
   					// check if the dependent component is valid 
   					if (!dependent.isValid())
   					{
   						validate = false;
   						break;
   					}
   					// check if the dependent component is visible and is attached to
   					// the page
   					else if (!dependent.isVisibleInHierarchy() || !dependent.isFormParticipant())
   					{
   						if (log.isWarnEnabled())
   						{
   							log.warn("IFormValidator in form `" +
   								getPageRelativePath() +
   								"` depends on a component that has been removed from the page or is no longer visible. " +
   								"Offending component id `" + dependent.getId() + "`.");
   						}
   						validate = false;
   						break;
   					}
   				}
   			}
   		}
   
   		if (validate)
   		{
   			validator.validate(this);
   		}
   	}



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@wicket.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] WICKET-7159 - Remove isEnabledInHierarchy condition from validate Form [wicket]

Posted by "papegaaij (via GitHub)" <gi...@apache.org>.
papegaaij commented on code in PR #1186:
URL: https://github.com/apache/wicket/pull/1186#discussion_r2154312103


##########
wicket-core/src/main/java/org/apache/wicket/markup/html/form/Form.java:
##########
@@ -1986,7 +1986,7 @@ protected final void validateFormValidator(final IFormValidator validator)
 				}
 				// check if the dependent component is visible and is attached to
 				// the page
-				else if (!dependent.isVisibleInHierarchy() || !dependent.isEnabledInHierarchy() || !dependent.isFormParticipant())

Review Comment:
   Thanks for the updates. This looks fine now. @pedrosans and @martin-g what do you think about this change? It's a minor change in behavior compared to previous 10.x versions, but IMHO this appraoch makes much more sense.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@wicket.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] WICKET-7159 - Remove isEnabledInHierarchy condition from validate Form [wicket]

Posted by "mira-silhavy (via GitHub)" <gi...@apache.org>.
mira-silhavy commented on code in PR #1186:
URL: https://github.com/apache/wicket/pull/1186#discussion_r2152208275


##########
wicket-core/src/main/java/org/apache/wicket/markup/html/form/Form.java:
##########
@@ -1986,7 +1986,7 @@ protected final void validateFormValidator(final IFormValidator validator)
 				}
 				// check if the dependent component is visible and is attached to
 				// the page
-				else if (!dependent.isVisibleInHierarchy() || !dependent.isEnabledInHierarchy() || !dependent.isFormParticipant())

Review Comment:
   I've pushed the change, now the validation only happens if there's at least 1 enabled dependent component. If the array is null the validation is now also skipped. Previously if the dependent form components was empty the validation still occur.



##########
wicket-core/src/main/java/org/apache/wicket/markup/html/form/Form.java:
##########
@@ -1986,7 +1986,7 @@ protected final void validateFormValidator(final IFormValidator validator)
 				}
 				// check if the dependent component is visible and is attached to
 				// the page
-				else if (!dependent.isVisibleInHierarchy() || !dependent.isEnabledInHierarchy() || !dependent.isFormParticipant())

Review Comment:
   I've pushed the change, now the validation only happens if there's at least 1 enabled dependent component. If the array is null the validation is now also skipped. Previously if the dependent form components was empty the validation still occurred.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@wicket.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] WICKET-7159 - Remove isEnabledInHierarchy condition from validate Form [wicket]

Posted by "mira-silhavy (via GitHub)" <gi...@apache.org>.
mira-silhavy commented on code in PR #1186:
URL: https://github.com/apache/wicket/pull/1186#discussion_r2167323973


##########
wicket-core/src/main/java/org/apache/wicket/markup/html/form/Form.java:
##########
@@ -1986,7 +1986,7 @@ protected final void validateFormValidator(final IFormValidator validator)
 				}
 				// check if the dependent component is visible and is attached to
 				// the page
-				else if (!dependent.isVisibleInHierarchy() || !dependent.isEnabledInHierarchy() || !dependent.isFormParticipant())

Review Comment:
   Hi @papegaaij, @martin-g I've pushed a fix to an older test. So that it does not return null from getDependentFormComponents.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@wicket.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] WICKET-7159 - Remove isEnabledInHierarchy condition from validate Form [wicket]

Posted by "papegaaij (via GitHub)" <gi...@apache.org>.
papegaaij commented on code in PR #1186:
URL: https://github.com/apache/wicket/pull/1186#discussion_r2145177740


##########
wicket-core/src/main/java/org/apache/wicket/markup/html/form/Form.java:
##########
@@ -1986,7 +1986,7 @@ protected final void validateFormValidator(final IFormValidator validator)
 				}
 				// check if the dependent component is visible and is attached to
 				// the page
-				else if (!dependent.isVisibleInHierarchy() || !dependent.isEnabledInHierarchy() || !dependent.isFormParticipant())

Review Comment:
   The problem I see with this approach is that the validator will also perform validation if all components are disabled. I don't think this is desired. Validation should only be performed if at least one component is enabled.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@wicket.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] WICKET-7159 - Remove isEnabledInHierarchy condition from validate Form [wicket]

Posted by "mira-silhavy (via GitHub)" <gi...@apache.org>.
mira-silhavy commented on code in PR #1186:
URL: https://github.com/apache/wicket/pull/1186#discussion_r2152864028


##########
wicket-core/src/main/java/org/apache/wicket/markup/html/form/Form.java:
##########
@@ -1986,7 +1986,7 @@ protected final void validateFormValidator(final IFormValidator validator)
 				}
 				// check if the dependent component is visible and is attached to
 				// the page
-				else if (!dependent.isVisibleInHierarchy() || !dependent.isEnabledInHierarchy() || !dependent.isFormParticipant())

Review Comment:
   Updated, added warning log message.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@wicket.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] WICKET-7159 - Remove isEnabledInHierarchy condition from validate Form [wicket]

Posted by "papegaaij (via GitHub)" <gi...@apache.org>.
papegaaij commented on code in PR #1186:
URL: https://github.com/apache/wicket/pull/1186#discussion_r2152829467


##########
wicket-core/src/main/java/org/apache/wicket/markup/html/form/Form.java:
##########
@@ -1986,7 +1986,7 @@ protected final void validateFormValidator(final IFormValidator validator)
 				}
 				// check if the dependent component is visible and is attached to
 				// the page
-				else if (!dependent.isVisibleInHierarchy() || !dependent.isEnabledInHierarchy() || !dependent.isFormParticipant())

Review Comment:
   I think this change looks good now. The warn below does need a small change, and I think it would be a good idea to also log a warning where you put the comment `// no enabled dependents, so no need to validate`. After all, the user did add this validator to the form, so he/she probably expected it to do something.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@wicket.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] WICKET-7159 - Remove isEnabledInHierarchy condition from validate Form [wicket]

Posted by "mira-silhavy (via GitHub)" <gi...@apache.org>.
mira-silhavy commented on code in PR #1186:
URL: https://github.com/apache/wicket/pull/1186#discussion_r2145192720


##########
wicket-core/src/main/java/org/apache/wicket/markup/html/form/Form.java:
##########
@@ -1986,7 +1986,7 @@ protected final void validateFormValidator(final IFormValidator validator)
 				}
 				// check if the dependent component is visible and is attached to
 				// the page
-				else if (!dependent.isVisibleInHierarchy() || !dependent.isEnabledInHierarchy() || !dependent.isFormParticipant())

Review Comment:
   Thanks @papegaaij, I'll update the validation.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@wicket.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org