Permalink
Browse files

Fix #349 be lenient on nested forms in PrimeFaces dialogs

  • Loading branch information...
1 parent eb8bdab commit 0215e13cff32fd467899bac76a9f3f5ce5c3eeae @BalusC BalusC committed Jan 31, 2017
@@ -65,6 +65,9 @@
private static final String RICHFACES_RLF_CLASS_NAME =
"org.richfaces.resource.ResourceLibraryFactoryImpl";
+ private static final Class<?> PRIMEFACES_DIALOG_CLASS =
+ toClassOrNull("org.primefaces.component.dialog.Dialog");
+
private static final String MYFACES_PACKAGE_PREFIX = "org.apache.myfaces.";
private static final String MYFACES_RENDERED_SCRIPT_RESOURCES_KEY =
"org.apache.myfaces.RENDERED_SCRIPT_RESOURCES_SET";
@@ -461,6 +464,24 @@ public static boolean isPrimeFacesDynamicResourceRequest(FacesContext context) {
return "primefaces".equals(params.get("ln")) && params.get("pfdrid") != null;
}
+ /**
+ * Returns true if the given component is nested in a PrimeFaces dialog.
+ * @param context The component to be checked.
+ * @return Whether the given component is nested in a PrimeFaces dialog.
+ * @since 2.6
+ */
+ public static boolean isNestedInPrimeFacesDialog(UIComponent component) {
+ if (PRIMEFACES_DIALOG_CLASS != null) {
+ for (UIComponent parent = component.getParent(); parent != null; parent = parent.getParent()) {
+ if (PRIMEFACES_DIALOG_CLASS.isAssignableFrom(parent.getClass())) {
+ return true;
+ }
+ }
+ }
+
+ return false;
+ }
+
// Tomcat related -------------------------------------------------------------------------------------------------
/**
@@ -214,7 +214,7 @@ public ViewHandler getWrapped() {
public void invoke(UIForm form) {
UIForm nestedParent = getClosestParent(form, UIForm.class);
- if (nestedParent != null) {
+ if (nestedParent != null && !Hacks.isNestedInPrimeFacesDialog(form)) {
throw new IllegalStateException(
format(ERROR_NESTED_FORM_ENCOUNTERED, form.getClientId(), nestedParent.getClientId()));
}

0 comments on commit 0215e13

Please sign in to comment.