Permalink
Browse files

#349 Cover case when dialog in turn nests another dialog

  • Loading branch information...
1 parent b2b7498 commit 3c2054fc7531c552e6f2a5213fd2780622570803 @BalusC BalusC committed Feb 1, 2017
@@ -29,6 +29,7 @@
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
@@ -466,13 +467,23 @@ public static boolean isPrimeFacesDynamicResourceRequest(FacesContext context) {
}
/**
- * Returns true if the given component is nested in a PrimeFaces dialog.
- * @param component The component to be checked.
- * @return Whether the given component is nested in a PrimeFaces dialog.
+ * Returns true if the given components are nested in (same) PrimeFaces dialog.
+ * @param components The components to be checked.
+ * @return Whether the given components are nested in (same) PrimeFaces dialog.
* @since 2.6
*/
- public static boolean isNestedInPrimeFacesDialog(UIComponent component) {
- return PRIMEFACES_DIALOG_CLASS != null && getClosestParent(component, PRIMEFACES_DIALOG_CLASS) != null;
+ public static boolean isNestedInPrimeFacesDialog(UIComponent... components) {
+ if (PRIMEFACES_DIALOG_CLASS == null) {
+ return false;
+ }
+
+ Set<UIComponent> dialogs = new HashSet<>();
+
+ for (UIComponent component : components) {
+ dialogs.add(getClosestParent(component, PRIMEFACES_DIALOG_CLASS));
+ }
+
+ return dialogs.size() == 1 && dialogs.iterator().next() != null;
}
// Tomcat related -------------------------------------------------------------------------------------------------
@@ -214,7 +214,7 @@ public ViewHandler getWrapped() {
public void invoke(UIForm form) {
UIForm nestedParent = getClosestParent(form, UIForm.class);
- if (nestedParent != null && (!Hacks.isNestedInPrimeFacesDialog(form) || Hacks.isNestedInPrimeFacesDialog(nestedParent))) {
+ if (nestedParent != null && (!Hacks.isNestedInPrimeFacesDialog(form) || Hacks.isNestedInPrimeFacesDialog(form, nestedParent))) {
throw new IllegalStateException(
format(ERROR_NESTED_FORM_ENCOUNTERED, form.getClientId(), nestedParent.getClientId()));
}

0 comments on commit 3c2054f

Please sign in to comment.