tandraschko commented on code in PR #484: URL: https://github.com/apache/myfaces/pull/484#discussion_r1073692899
########## impl/src/main/java/org/apache/myfaces/component/validate/ValidateWholeBeanComponent.java: ########## @@ -55,6 +62,79 @@ public void addValidator(Validator validator) // No-op. It does not make sense to allow additional validators to be installed. } + + @Override + public void encodeBegin(FacesContext context) throws IOException + { + UIComponent parent = this.getParent(); + + // find a parent form + while (parent != null & !(parent instanceof jakarta.faces.component.UIForm)) + { + parent = parent.getParent(); + } + + if (!(parent instanceof jakarta.faces.component.UIForm)) + { + // Throw an exception just as Mojarra + throw new IllegalStateException("f:validateWholeBean must be placed within a form"); + } + + validateTagPlacement(parent, this.getClientId(context)); + } + + /* + * As required by https://github.com/jakartaee/faces/issues/1 + * Also ensures all inputs are available for f:wholeBeanValidate processing + * (otherwise they'd be empty during the validation) + * Based off Mojarra's UIValidateWholeBean#misplacedComponentCheck + * 1) Reverse the list of child elements in the form + * 2) Loop thorough each child and nested elements (if any) + * 3) If we find an input tag (EditableValueHolder) + * and it's group validator matches f:wholeBeanValidate (this part is unique to myfaces) + * then throw an exception. + * 4) If we find the f:wholeBeanValidate's client id before any EditableValueHolder tags, return. + */ + public void validateTagPlacement(UIComponent component, String clientId) + throws IllegalStateException + { + List<UIComponent> children = component.getChildren(); + List<UIComponent> reversed = new ArrayList<UIComponent>(); + + for (int i = children.size() - 1; i >= 0; i--) + { + reversed.add(children.get(i)); + } + + for (UIComponent c : reversed) + { + if (c instanceof EditableValueHolder && !(c instanceof ValidateWholeBeanComponent)) + { + Validator[] validators = ((EditableValueHolder) c).getValidators(); + for (Validator v : validators) + { + if (v instanceof BeanValidator + && ((BeanValidator) v).getValidationGroups().equals(this.getValidationGroups())) + { + System.out.println(((BeanValidator) v).getValidationGroups()); Review Comment: remove -- 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