You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lu...@apache.org on 2011/10/26 04:45:59 UTC
svn commit: r1189010 -
/myfaces/core/trunk/api/src/main/java/javax/faces/component/UIForm.java
Author: lu4242
Date: Wed Oct 26 02:45:59 2011
New Revision: 1189010
URL: http://svn.apache.org/viewvc?rev=1189010&view=rev
Log:
MYFACES-3373 UIForm.createUniqueId should take into account prependId logic
Modified:
myfaces/core/trunk/api/src/main/java/javax/faces/component/UIForm.java
Modified: myfaces/core/trunk/api/src/main/java/javax/faces/component/UIForm.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/java/javax/faces/component/UIForm.java?rev=1189010&r1=1189009&r2=1189010&view=diff
==============================================================================
--- myfaces/core/trunk/api/src/main/java/javax/faces/component/UIForm.java (original)
+++ myfaces/core/trunk/api/src/main/java/javax/faces/component/UIForm.java Wed Oct 26 02:45:59 2011
@@ -21,12 +21,15 @@ package javax.faces.component;
import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFComponent;
import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFProperty;
+import javax.faces.FacesException;
import javax.faces.component.visit.VisitCallback;
import javax.faces.component.visit.VisitContext;
import javax.faces.component.visit.VisitResult;
import javax.faces.context.FacesContext;
import javax.faces.event.PostValidateEvent;
import javax.faces.event.PreValidateEvent;
+import javax.faces.view.Location;
+
import java.util.Collection;
/**
@@ -50,7 +53,40 @@ public class UIForm extends UIComponentB
*/
public String createUniqueId(FacesContext context, String seed)
{
- StringBuilder bld = __getSharedStringBuilder(context);
+ StringBuilder bld = null;
+
+ if (!isPrependId())
+ {
+ bld = new StringBuilder();
+ UniqueIdVendor parentUniqueIdVendor = _ComponentUtils.findParentUniqueIdVendor(this);
+ if (parentUniqueIdVendor == null)
+ {
+ UIViewRoot viewRoot = context.getViewRoot();
+ if (viewRoot != null)
+ {
+ bld.append(viewRoot.createUniqueId());
+ bld.append('_');
+ }
+ else
+ {
+ // The RI throws a NPE
+ String location = getComponentLocation(this);
+ throw new FacesException("Cannot create clientId. No id is assigned for component"
+ + " to create an id and UIViewRoot is not defined: "
+ + getPathToComponent(this)
+ + (location != null ? " created from: " + location : ""));
+ }
+ }
+ else
+ {
+ bld.append(parentUniqueIdVendor.createUniqueId(context, null));
+ bld.append('_');
+ }
+ }
+ else
+ {
+ bld = __getSharedStringBuilder(context);
+ }
Long uniqueIdCounter = (Long) getStateHelper().get(PropertyKeys.uniqueIdCounter);
uniqueIdCounter = (uniqueIdCounter == null) ? 0 : uniqueIdCounter;
@@ -68,7 +104,7 @@ public class UIForm extends UIComponentB
return bld.append(UIViewRoot.UNIQUE_ID_PREFIX).append(seed).toString();
}
}
-
+
public boolean isSubmitted()
{
//return _submitted;
@@ -357,6 +393,64 @@ public class UIForm extends UIComponentB
return COMPONENT_FAMILY;
}
+ private String getComponentLocation(UIComponent component)
+ {
+ Location location = (Location) component.getAttributes()
+ .get(UIComponent.VIEW_LOCATION_KEY);
+ if (location != null)
+ {
+ return location.toString();
+ }
+ return null;
+ }
+
+ private String getPathToComponent(UIComponent component)
+ {
+ StringBuffer buf = new StringBuffer();
+
+ if (component == null)
+ {
+ buf.append("{Component-Path : ");
+ buf.append("[null]}");
+ return buf.toString();
+ }
+
+ getPathToComponent(component, buf);
+
+ buf.insert(0, "{Component-Path : ");
+ buf.append("}");
+
+ return buf.toString();
+ }
+
+ private void getPathToComponent(UIComponent component, StringBuffer buf)
+ {
+ if (component == null)
+ {
+ return;
+ }
+
+ StringBuffer intBuf = new StringBuffer();
+
+ intBuf.append("[Class: ");
+ intBuf.append(component.getClass().getName());
+ if (component instanceof UIViewRoot)
+ {
+ intBuf.append(",ViewId: ");
+ intBuf.append(((UIViewRoot) component).getViewId());
+ }
+ else
+ {
+ intBuf.append(",Id: ");
+ intBuf.append(component.getId());
+ }
+ intBuf.append("]");
+
+ buf.insert(0, intBuf.toString());
+
+ getPathToComponent(component.getParent(), buf);
+ }
+
// ------------------ GENERATED CODE END ---------------------------------------
@Override