[seam-commits] Seam SVN: r9861 - trunk/ui/src/main/java/org/jboss/seam/ui/validator.
seam-commits at lists.jboss.org
seam-commits at lists.jboss.org
Sun Jan 4 16:21:14 EST 2009
Author: danielc.roth
Date: 2009-01-04 16:21:13 -0500 (Sun, 04 Jan 2009)
New Revision: 9861
Modified:
trunk/ui/src/main/java/org/jboss/seam/ui/validator/EqualityValidator.java
Log:
JBSEAM-3676
Modified: trunk/ui/src/main/java/org/jboss/seam/ui/validator/EqualityValidator.java
===================================================================
--- trunk/ui/src/main/java/org/jboss/seam/ui/validator/EqualityValidator.java 2009-01-04 19:52:09 UTC (rev 9860)
+++ trunk/ui/src/main/java/org/jboss/seam/ui/validator/EqualityValidator.java 2009-01-04 21:21:13 UTC (rev 9861)
@@ -6,6 +6,7 @@
import javax.faces.application.Application;
import javax.faces.application.FacesMessage;
import javax.faces.component.EditableValueHolder;
+import javax.faces.component.NamingContainer;
import javax.faces.component.StateHolder;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
@@ -18,6 +19,7 @@
import org.jboss.seam.faces.FacesMessages;
import org.jboss.seam.log.LogProvider;
import org.jboss.seam.log.Logging;
+import org.jboss.seam.ui.component.UIDecorate;
/**
* Validate two fields are equal
@@ -90,12 +92,12 @@
public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException
{
- String forId = getFor();
- if (forId == null)
+ if (getFor() == null)
{
throw new FacesException("Must specify a component to validate equality against");
}
- UIComponent otherComponent = component.findComponent(forId);
+ UIComponent otherComponent = findOtherComponent(component);
+
Object other = new OtherComponent(context, otherComponent).getValue();
if (value == null && other == null)
{
@@ -145,6 +147,49 @@
}
}
+ private UIComponent findOtherComponent(UIComponent component)
+ {
+ UIComponent otherComponent = component.findComponent(getFor());
+
+ /**
+ * If s:decorate is used, otherComponent will be null We have to look it
+ * up ourselves
+ */
+ if (otherComponent == null)
+ {
+ UIComponent decorateParent = null;
+ UIComponent parent = component.getParent();
+ while (decorateParent == null && parent != null)
+ {
+ if (parent instanceof NamingContainer && !(parent instanceof UIDecorate))
+ {
+ decorateParent = parent;
+ }
+ parent = parent.getParent();
+ }
+ if (decorateParent != null)
+ otherComponent = findChildComponent(decorateParent);
+
+ }
+ return otherComponent;
+ }
+
+ private UIComponent findChildComponent(UIComponent parent)
+ {
+ UIComponent ret = null;
+ for (UIComponent child : parent.getChildren())
+ {
+ if (child.getId().equals(getFor()))
+ ret = child;
+ else
+ ret = findChildComponent(child);
+ if (ret != null)
+ break;
+ }
+ return ret;
+
+ }
+
private int compare(Object value, Object other) throws IllegalArgumentException
{
try
More information about the seam-commits
mailing list