Permalink
Browse files

Fix #48 Fix broken Components#hasInvokedSubmit() in iterating components

and improved #stripIterationIndexFromClientId() helper.
  • Loading branch information...
BalusC committed Aug 9, 2014
1 parent 94d0220 commit 9870108fdf6b2dec0f9c58e81ecac8f5c57051ec
Showing with 28 additions and 11 deletions.
  1. +28 −11 src/main/java/org/omnifaces/util/Components.java
@@ -13,6 +13,7 @@
package org.omnifaces.util;
import static java.util.Arrays.asList;
import static java.util.regex.Pattern.quote;
import static javax.faces.component.visit.VisitContext.createVisitContext;
import static javax.faces.component.visit.VisitResult.ACCEPT;
import static org.omnifaces.util.Faces.getContext;
@@ -42,6 +43,7 @@
import javax.faces.component.UIComponentBase;
import javax.faces.component.UIForm;
import javax.faces.component.UIInput;
import javax.faces.component.UINamingContainer;
import javax.faces.component.UIPanel;
import javax.faces.component.UIViewRoot;
import javax.faces.component.behavior.AjaxBehavior;
@@ -814,20 +816,34 @@ public static boolean hasSubmittedValue(EditableValueHolder component) {
public static boolean hasInvokedSubmit(UIComponent component) {
FacesContext context = FacesContext.getCurrentInstance();
if (context.isPostback()) {
String clientId = component.getClientId(context);
Map<String, String> params = context.getExternalContext().getRequestParameterMap();
if (!context.isPostback()) {
return false;
}
if (context.getPartialViewContext().isAjaxRequest()) {
return clientId.equals(params.get("javax.faces.source"));
}
else {
return component instanceof UICommand && params.get(clientId) != null;
String clientId = stripIterationIndexFromClientId(component.getClientId(context));
Map<String, String> params = context.getExternalContext().getRequestParameterMap();
if (context.getPartialViewContext().isAjaxRequest()) {
String source = params.get("javax.faces.source");
if (source != null) {
return clientId.equals(stripIterationIndexFromClientId(source));
}
}
else {
return false;
if (component instanceof UICommand) {
for (String name : params.keySet()) {
if (name.startsWith("javax.faces.")) {
continue; // Quick skip.
}
if (clientId.equals(stripIterationIndexFromClientId(name))) {
return true;
}
}
}
return false;
}
// Expressions ----------------------------------------------------------------------------------------------------
@@ -1013,7 +1029,8 @@ public static void validateHasNoChildren(UIComponent component) throws IllegalAr
* Strip UIData/UIRepeat iteration index in pattern <code>:[0-9+]:</code> from given component client ID.
*/
private static String stripIterationIndexFromClientId(String clientId) {
return clientId.replaceAll(":[0-9]+:", ":");
String separatorChar = Character.toString(UINamingContainer.getSeparatorChar(getContext()));
return clientId.replaceAll(quote(separatorChar) + "[0-9]+" + quote(separatorChar), separatorChar);
}
/**

0 comments on commit 9870108

Please sign in to comment.