[GitHub] [myfaces] volosied commented on a diff in pull request #492: MYFACES-4551: Allow group validation for uiselectone elements
volosied commented on code in PR #492: URL: https://github.com/apache/myfaces/pull/492#discussion_r1087077197 ## api/src/main/java/jakarta/faces/component/UISelectOne.java: ## @@ -90,37 +91,43 @@ public void processValidators(FacesContext context) @Override public VisitResult visit(VisitContext visitContext, UIComponent target) { +// check they they are of the same group if (target instanceof UISelectOne && ((UISelectOne) target).getGroup().equals(group)) { -UISelectOne radio = (UISelectOne) target; - -// if target is an instance of UISelectOne then get all the UISelectItem children -// and verify if the submitted value exists -for (Iterator iter = radio.getChildren().iterator(); iter.hasNext(); ) -{ -UIComponent component = iter.next(); -if (component instanceof UISelectItem) -{ -UISelectItem item = (UISelectItem) component; -if (item.getItemValue().equals(submittedValue)) -{ -selectItemValueFound = true; -return VisitResult.COMPLETE; -} -} - -} -return VisitResult.REJECT; Review Comment: Additionally, the current code causes a failure with the Spec329 test: ``` Caused by: java.lang.ClassCastException: class java.lang.String cannot be cast to class ee.jakarta.tck.faces.test.javaee8.uiinput.Spec329Entity (java.lang.String is in module java.base of loader 'bootstrap'; ee.jakarta.tck.faces.test.javaee8.uiinput.Spec329Entity is in unnamed module of loader com.ibm.ws.classloading.internal.AppClassLoader @e7d2dc5) at ee.jakarta.tck.faces.test.javaee8.uiinput.Spec329Entity.equals(Spec329Entity.java:33) at jakarta.faces.component.UISelectOne$1.visit(UISelectOne.java:105) at org.apache.myfaces.component.visit.FullVisitContext.invokeVisitCallback(FullVisitContext.java:140) at jakarta.faces.component.UIComponent.visitTree(UIComponent.java:873) at jakarta.faces.component.UIComponentBase.visitTree(UIComponentBase.java:1120) at jakarta.faces.component.UIData.visitTree(UIData.java:2234) at jakarta.faces.component.UIForm.visitTree(UIForm.java:343) at jakarta.faces.component.UISelectOne.processValidators(UISelectOne.java:88) ``` The new code works fine for me and if you submit some other value in the form (other than the available options), you'll just get this type of error. ```inDataTableWithEntityList:table:0:radio: Validation Error: Value is not valid``` As far as I can tell, this code is good. -- 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: dev-unsubscr...@myfaces.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
[GitHub] [myfaces] volosied commented on a diff in pull request #492: MYFACES-4551: Allow group validation for uiselectone elements
volosied commented on code in PR #492: URL: https://github.com/apache/myfaces/pull/492#discussion_r1087077197 ## api/src/main/java/jakarta/faces/component/UISelectOne.java: ## @@ -90,37 +91,43 @@ public void processValidators(FacesContext context) @Override public VisitResult visit(VisitContext visitContext, UIComponent target) { +// check they they are of the same group if (target instanceof UISelectOne && ((UISelectOne) target).getGroup().equals(group)) { -UISelectOne radio = (UISelectOne) target; - -// if target is an instance of UISelectOne then get all the UISelectItem children -// and verify if the submitted value exists -for (Iterator iter = radio.getChildren().iterator(); iter.hasNext(); ) -{ -UIComponent component = iter.next(); -if (component instanceof UISelectItem) -{ -UISelectItem item = (UISelectItem) component; -if (item.getItemValue().equals(submittedValue)) -{ -selectItemValueFound = true; -return VisitResult.COMPLETE; -} -} - -} -return VisitResult.REJECT; Review Comment: Additionally, the current code causes a failure with the Spec329 test: ``` Caused by: java.lang.ClassCastException: class java.lang.String cannot be cast to class ee.jakarta.tck.faces.test.javaee8.uiinput.Spec329Entity (java.lang.String is in module java.base of loader 'bootstrap'; ee.jakarta.tck.faces.test.javaee8.uiinput.Spec329Entity is in unnamed module of loader com.ibm.ws.classloading.internal.AppClassLoader @e7d2dc5) at ee.jakarta.tck.faces.test.javaee8.uiinput.Spec329Entity.equals(Spec329Entity.java:33) at jakarta.faces.component.UISelectOne$1.visit(UISelectOne.java:105) at org.apache.myfaces.component.visit.FullVisitContext.invokeVisitCallback(FullVisitContext.java:140) at jakarta.faces.component.UIComponent.visitTree(UIComponent.java:873) at jakarta.faces.component.UIComponentBase.visitTree(UIComponentBase.java:1120) at jakarta.faces.component.UIData.visitTree(UIData.java:2234) at jakarta.faces.component.UIForm.visitTree(UIForm.java:343) at jakarta.faces.component.UISelectOne.processValidators(UISelectOne.java:88) ``` The new work works fine for me and if you use submit some other value in the form (other than the available options), you'll just get this type of error. ```inDataTableWithEntityList:table:0:radio: Validation Error: Value is not valid``` As far as I can tell, this code is good. -- 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: dev-unsubscr...@myfaces.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
[GitHub] [myfaces] volosied commented on a diff in pull request #492: MYFACES-4551: Allow group validation for uiselectone elements
volosied commented on code in PR #492: URL: https://github.com/apache/myfaces/pull/492#discussion_r1087077197 ## api/src/main/java/jakarta/faces/component/UISelectOne.java: ## @@ -90,37 +91,43 @@ public void processValidators(FacesContext context) @Override public VisitResult visit(VisitContext visitContext, UIComponent target) { +// check they they are of the same group if (target instanceof UISelectOne && ((UISelectOne) target).getGroup().equals(group)) { -UISelectOne radio = (UISelectOne) target; - -// if target is an instance of UISelectOne then get all the UISelectItem children -// and verify if the submitted value exists -for (Iterator iter = radio.getChildren().iterator(); iter.hasNext(); ) -{ -UIComponent component = iter.next(); -if (component instanceof UISelectItem) -{ -UISelectItem item = (UISelectItem) component; -if (item.getItemValue().equals(submittedValue)) -{ -selectItemValueFound = true; -return VisitResult.COMPLETE; -} -} - -} -return VisitResult.REJECT; Review Comment: Additionally, the current code causes a failure with the Spec329 test: ``` Caused by: java.lang.ClassCastException: class java.lang.String cannot be cast to class ee.jakarta.tck.faces.test.javaee8.uiinput.Spec329Entity (java.lang.String is in module java.base of loader 'bootstrap'; ee.jakarta.tck.faces.test.javaee8.uiinput.Spec329Entity is in unnamed module of loader com.ibm.ws.classloading.internal.AppClassLoader @e7d2dc5) at ee.jakarta.tck.faces.test.javaee8.uiinput.Spec329Entity.equals(Spec329Entity.java:33) ``` The new work works fine for me and if you use submit some other value in the form (other than the available options), you'll just get this type of error. ```inDataTableWithEntityList:table:0:radio: Validation Error: Value is not valid``` As far as I can tell, this code is good. -- 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: dev-unsubscr...@myfaces.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
[GitHub] [myfaces] volosied commented on a diff in pull request #492: MYFACES-4551: Allow group validation for uiselectone elements
volosied commented on code in PR #492: URL: https://github.com/apache/myfaces/pull/492#discussion_r1085984802 ## api/src/main/java/jakarta/faces/component/UISelectOne.java: ## @@ -90,37 +91,43 @@ public void processValidators(FacesContext context) @Override public VisitResult visit(VisitContext visitContext, UIComponent target) { +// check they they are of the same group if (target instanceof UISelectOne && ((UISelectOne) target).getGroup().equals(group)) { -UISelectOne radio = (UISelectOne) target; - -// if target is an instance of UISelectOne then get all the UISelectItem children -// and verify if the submitted value exists -for (Iterator iter = radio.getChildren().iterator(); iter.hasNext(); ) -{ -UIComponent component = iter.next(); -if (component instanceof UISelectItem) -{ -UISelectItem item = (UISelectItem) component; -if (item.getItemValue().equals(submittedValue)) -{ -selectItemValueFound = true; -return VisitResult.COMPLETE; -} -} - -} -return VisitResult.REJECT; Review Comment: My understanding is that submittedValue is checked via UISelectOne#validateValue which calls into: https://github.com/apache/myfaces/blob/89c747e85615e3f33265e664c8361789f38ea7db/api/src/main/java/org/apache/myfaces/core/api/shared/SelectItemsUtil.java#L177 Additionally, the spec does not ask for the `item.getItemValue().equals(submittedValue)` / `component instanceof UISelectItem` checks here. https://jakarta.ee/specifications/faces/4.0/apidocs/jakarta/faces/component/uiselectone#processValidators(jakarta.faces.context.FacesContext) -- 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: dev-unsubscr...@myfaces.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
[GitHub] [myfaces] volosied commented on a diff in pull request #492: MYFACES-4551: Allow group validation for uiselectone elements
volosied commented on code in PR #492: URL: https://github.com/apache/myfaces/pull/492#discussion_r1084408193 ## impl/src/main/java/org/apache/myfaces/renderkit/html/util/HtmlRendererUtils.java: ## @@ -292,6 +292,12 @@ public static void decodeUISelectOne(FacesContext facesContext, UIComponent comp callback); } } +else +{ +// means input was not submitted. set to empty string so we can validate required fields +// if not set, a null value will skip validation -- see beginning of UIInput#validate + ((EditableValueHolder)component).setSubmittedValue(RendererUtils.EMPTY_STRING); Review Comment: Not sure if enums are spec allowed due to this isEmpty() definition: https://jakarta.ee/specifications/faces/4.0/apidocs/jakarta/faces/component/uiinput#isEmpty(java.lang.Object) ``` If the value is null, return true. If the value is a String and it is the empty string, return true. If the value is an array and the array length is 0, return true. If the value is a List and the List is empty, return true. If the value is a Collection and the Collection is empty, return true. If the value is a Map and the Map is empty, return true. In all other cases, return false. ``` I think we will need to keep it as is (set to empty string when no value submitted, if kept as null it would cause validation to be skipped -- https://github.com/apache/myfaces/blob/e9fe59f96410f31a7f5c0fbd6838c1a22683a691/api/src/main/java/jakarta/faces/component/UIInput.java#L650 required is true, but shouldAlwaysPerformValidationWhenRequiredTrue is false) -- 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: dev-unsubscr...@myfaces.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
[GitHub] [myfaces] volosied commented on a diff in pull request #492: MYFACES-4551: Allow group validation for uiselectone elements
volosied commented on code in PR #492: URL: https://github.com/apache/myfaces/pull/492#discussion_r1084408193 ## impl/src/main/java/org/apache/myfaces/renderkit/html/util/HtmlRendererUtils.java: ## @@ -292,6 +292,12 @@ public static void decodeUISelectOne(FacesContext facesContext, UIComponent comp callback); } } +else +{ +// means input was not submitted. set to empty string so we can validate required fields +// if not set, a null value will skip validation -- see beginning of UIInput#validate + ((EditableValueHolder)component).setSubmittedValue(RendererUtils.EMPTY_STRING); Review Comment: Not sure if enums are spec allowed due to this isEmpty() definition: https://jakarta.ee/specifications/faces/4.0/apidocs/jakarta/faces/component/uiinput#isEmpty(java.lang.Object) ``` If the value is null, return true. If the value is a String and it is the empty string, return true. If the value is an array and the array length is 0, return true. If the value is a List and the List is empty, return true. If the value is a Collection and the Collection is empty, return true. If the value is a Map and the Map is empty, return true. In all other cases, return false. ``` I think we will need to keep it as is (set to empty string when no value submitted, if kept as null it would cause validation to be skipped) -- 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: dev-unsubscr...@myfaces.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
[GitHub] [myfaces] volosied commented on a diff in pull request #492: MYFACES-4551: Allow group validation for uiselectone elements
volosied commented on code in PR #492: URL: https://github.com/apache/myfaces/pull/492#discussion_r1082910214 ## impl/src/main/java/org/apache/myfaces/renderkit/html/util/HtmlRendererUtils.java: ## @@ -292,6 +292,12 @@ public static void decodeUISelectOne(FacesContext facesContext, UIComponent comp callback); } } +else +{ +// means input was not submitted. set to empty string so we can validate required fields +// if not set, a null value will skip validation -- see beginning of UIInput#validate + ((EditableValueHolder)component).setSubmittedValue(RendererUtils.EMPTY_STRING); Review Comment: Setting to RendererUtils.EMPTY_STRING, similar as to Line 322 & 245 Not a fan of using an empty string here ( since it's later converted to a null), maybe an enum would be better...? -- 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: dev-unsubscr...@myfaces.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
[GitHub] [myfaces] volosied commented on a diff in pull request #492: MYFACES-4551: Allow group validation for uiselectone elements
volosied commented on code in PR #492: URL: https://github.com/apache/myfaces/pull/492#discussion_r1082923271 ## api/src/main/java/jakarta/faces/component/UISelectOne.java: ## @@ -69,19 +69,20 @@ public String getFamily() } /** - * Verify that when ever there is a ValueExpression and submitted value is not empty, then + * Check whether a group exists and then * visit all the UISelectItem elements within the UISelectOne radio components to check if - * the submitted value exists in any of the select items. + * the submitted value is empty (ie. not submitted) or if a previous group item has been + * has failed to be validated (if no so further validation processing is needed) * * @see jakarta.faces.component.UIInput#processValidators(jakarta.faces.context.FacesContext) */ @Override public void processValidators(FacesContext context) { String group = getGroup(); -ValueExpression ve = getValueExpression("value"); String submittedValue = (String) getSubmittedValue(); -if (group != null && !group.isEmpty() && ve != null && !isEmpty(submittedValue)) + +if (group != null && !group.isEmpty()) Review Comment: I need to check for the "non-empty UIInput.getSubmittedValue()" case. -- 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: dev-unsubscr...@myfaces.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
[GitHub] [myfaces] volosied commented on a diff in pull request #492: MYFACES-4551: Allow group validation for uiselectone elements
volosied commented on code in PR #492: URL: https://github.com/apache/myfaces/pull/492#discussion_r1082920876 ## api/src/main/java/jakarta/faces/component/UISelectOne.java: ## @@ -69,19 +69,20 @@ public String getFamily() } /** - * Verify that when ever there is a ValueExpression and submitted value is not empty, then + * Check whether a group exists and then * visit all the UISelectItem elements within the UISelectOne radio components to check if - * the submitted value exists in any of the select items. + * the submitted value is empty (ie. not submitted) or if a previous group item has been + * has failed to be validated (if no so further validation processing is needed) * * @see jakarta.faces.component.UIInput#processValidators(jakarta.faces.context.FacesContext) */ @Override public void processValidators(FacesContext context) { String group = getGroup(); -ValueExpression ve = getValueExpression("value"); String submittedValue = (String) getSubmittedValue(); -if (group != null && !group.isEmpty() && ve != null && !isEmpty(submittedValue)) + +if (group != null && !group.isEmpty()) Review Comment: Relevant spec: https://jakarta.ee/specifications/faces/4.0/apidocs/jakarta/faces/component/uiselectone#processValidators(jakarta.faces.context.FacesContext) If [getGroup()](https://jakarta.ee/specifications/faces/4.0/apidocs/jakarta/faces/component/uiselectone#getGroup()) is set, and [UIInput.getSubmittedValue()](https://jakarta.ee/specifications/faces/4.0/apidocs/jakarta/faces/component/UIInput.html#getSubmittedValue()) is empty, and at least one other component having the same group within a UIForm parent has a non-empty [UIInput.getSubmittedValue()](https://jakarta.ee/specifications/faces/4.0/apidocs/jakarta/faces/component/UIInput.html#getSubmittedValue()) or returns true on [UIInput.isLocalValueSet()](https://jakarta.ee/specifications/faces/4.0/apidocs/jakarta/faces/component/UIInput.html#isLocalValueSet()) or returns false on [UIInput.isValid()](https://jakarta.ee/specifications/faces/4.0/apidocs/jakarta/faces/component/UIInput.html#isValid()), then skip validation for current component, else perform standard superclass processing by super.processValidators(context). -- 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: dev-unsubscr...@myfaces.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
[GitHub] [myfaces] volosied commented on a diff in pull request #492: MYFACES-4551: Allow group validation for uiselectone elements
volosied commented on code in PR #492: URL: https://github.com/apache/myfaces/pull/492#discussion_r1082861220 ## impl/src/main/java/org/apache/myfaces/renderkit/RendererUtils.java: ## @@ -693,17 +693,25 @@ else if (allowNonArrayOrCollectionValue) public static Object getConvertedUISelectOneValue( FacesContext facesContext, UISelectOne output, Object submittedValue) { -if (submittedValue != null && !(submittedValue instanceof String)) + +if(submittedValue == null) +{ +if (log.isLoggable(Level.FINE)) +{ +log.fine("No conversion necessary for null uiselectone value: client id " + output.getClientId()); +} +return null; Review Comment: Mojarra returns null and so I did the same here ( since no value is submitted) I'm just not sure if this is correct, however. Should this be brought up in a challenge, perhaps? -- 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: dev-unsubscr...@myfaces.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
[GitHub] [myfaces] volosied commented on a diff in pull request #492: MYFACES-4551: Allow group validation for uiselectone elements
volosied commented on code in PR #492: URL: https://github.com/apache/myfaces/pull/492#discussion_r1082912449 ## impl/src/main/java/org/apache/myfaces/renderkit/RendererUtils.java: ## @@ -693,17 +693,25 @@ else if (allowNonArrayOrCollectionValue) public static Object getConvertedUISelectOneValue( FacesContext facesContext, UISelectOne output, Object submittedValue) { -if (submittedValue != null && !(submittedValue instanceof String)) + +if(submittedValue == null) +{ +if (log.isLoggable(Level.FINE)) +{ +log.fine("No conversion necessary for null uiselectone value: client id " + output.getClientId()); +} +return null; Review Comment: Might be worth a challenge? Unless we switch to enums which would signify that no value is inputted, hence no conversion necessary (rather than rely on this empty string / null nonsense). -- 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: dev-unsubscr...@myfaces.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
[GitHub] [myfaces] volosied commented on a diff in pull request #492: MYFACES-4551: Allow group validation for uiselectone elements
volosied commented on code in PR #492: URL: https://github.com/apache/myfaces/pull/492#discussion_r1082910214 ## impl/src/main/java/org/apache/myfaces/renderkit/html/util/HtmlRendererUtils.java: ## @@ -292,6 +292,12 @@ public static void decodeUISelectOne(FacesContext facesContext, UIComponent comp callback); } } +else +{ +// means input was not submitted. set to empty string so we can validate required fields +// if not set, a null value will skip validation -- see beginning of UIInput#validate + ((EditableValueHolder)component).setSubmittedValue(RendererUtils.EMPTY_STRING); Review Comment: Setting to RendererUtils.EMPTY_STRING, similar as to Line 322 & 245 Not a fan of using an empty string here ( since it's latter converted to a null), maybe an enum would be better...? -- 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: dev-unsubscr...@myfaces.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
[GitHub] [myfaces] volosied commented on a diff in pull request #492: MYFACES-4551: Allow group validation for uiselectone elements
volosied commented on code in PR #492: URL: https://github.com/apache/myfaces/pull/492#discussion_r1082867841 ## api/src/main/java/jakarta/faces/component/UISelectOne.java: ## @@ -69,19 +69,20 @@ public String getFamily() } /** - * Verify that when ever there is a ValueExpression and submitted value is not empty, then + * Check whether a group exists and then * visit all the UISelectItem elements within the UISelectOne radio components to check if - * the submitted value exists in any of the select items. + * the submitted value is empty (ie. not submitted) or if a previous group item has been + * has failed to be validated (if no so further validation processing is needed) * * @see jakarta.faces.component.UIInput#processValidators(jakarta.faces.context.FacesContext) */ @Override public void processValidators(FacesContext context) { String group = getGroup(); -ValueExpression ve = getValueExpression("value"); Review Comment: ValueExpression was removed because not all scenario uses a VE in the TCK test, i.e: ` ` -- 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: dev-unsubscr...@myfaces.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
[GitHub] [myfaces] volosied commented on a diff in pull request #492: MYFACES-4551: Allow group validation for uiselectone elements
volosied commented on code in PR #492: URL: https://github.com/apache/myfaces/pull/492#discussion_r1082861220 ## impl/src/main/java/org/apache/myfaces/renderkit/RendererUtils.java: ## @@ -693,17 +693,25 @@ else if (allowNonArrayOrCollectionValue) public static Object getConvertedUISelectOneValue( FacesContext facesContext, UISelectOne output, Object submittedValue) { -if (submittedValue != null && !(submittedValue instanceof String)) + +if(submittedValue == null) +{ +if (log.isLoggable(Level.FINE)) +{ +log.fine("No conversion necessary for null uiselectone value: client id " + output.getClientId()); +} +return null; Review Comment: Mojarra returns null and so I did the same here ( since no value is submitted) I'm just not sure if this is correct, however. -- 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: dev-unsubscr...@myfaces.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org