### Eclipse Workspace Patch 1.0
#P org.jboss.tools.vpe
Index: src/org/jboss/tools/vpe/editor/mapping/VpeDomMapping.java
===================================================================
--- src/org/jboss/tools/vpe/editor/mapping/VpeDomMapping.java	(revision 36765)
+++ src/org/jboss/tools/vpe/editor/mapping/VpeDomMapping.java	(working copy)
@@ -72,19 +72,11 @@
 	public VpeNodeMapping getNodeMappingAtVisualNode(nsIDOMNode visualNode) {
 		VpeNodeMapping nodeMapping = null;
 		/*
-		 * See https://issues.jboss.org/browse/JBIDE-9807
-		 * Method map.get(key) doesn't work correctly for this situation,
-		 * it happens because "visualMap.keySet().contains(visualNode)" 
-		 * not always correctly determines the "visualNode".
+		 * https://issues.jboss.org/browse/JBIDE-9932
+		 * Replaced with map.
 		 */
 		if (visualNode != null) {
-			Iterator<Map.Entry<nsIDOMNode, VpeNodeMapping>> iter = visualMap.entrySet().iterator();
-			while(iter.hasNext()) {
-				Map.Entry<nsIDOMNode,VpeNodeMapping> element = iter.next();
-				if (visualNode.equals(element.getKey())) {
-					nodeMapping = element.getValue();
-				}
-			}
+			nodeMapping = visualMap.get(visualNode);
 		}
 		return nodeMapping;
 	}
Index: src/org/jboss/tools/vpe/editor/VpeVisualDomBuilder.java
===================================================================
--- src/org/jboss/tools/vpe/editor/VpeVisualDomBuilder.java	(revision 36765)
+++ src/org/jboss/tools/vpe/editor/VpeVisualDomBuilder.java	(working copy)
@@ -262,10 +262,7 @@
 	 */
 	private boolean addNode(Node sourceNode, nsIDOMNode visualNextNode, nsIDOMNode visualContainer) {
 		try {
-
-		nsIDOMNode visualNewNode = createNode(sourceNode, visualContainer);
-
-			
+		VpeElementMapping elementMapping = createNode(sourceNode, visualContainer);
 // Commented as fix for JBIDE-3012.	
 //		// Fix for JBIDE-1097
 //		try {
@@ -277,35 +274,46 @@
 //		} catch (XPCOMException ex) {
 //			// just ignore this exception
 //		}
-
-		if (visualNewNode != null) {
-			/*
-			 * https://jira.jboss.org/jira/browse/JBIDE-3373
-			 * Do not add additional visual node for f:facet
-			 * when it is inserted into existing one.
-			 */
-			nsIDOMElement element = null;
-			try {
-				element = queryInterface(visualNewNode, nsIDOMElement.class);
-			} catch (org.mozilla.xpcom.XPCOMException e) {
-				/*
-				 * Cannot parse node to element,
-				 * do nothing
-				 */
-		 	}
-			if (!((null != element) && element.hasAttribute(VPE_FACET))) {
-				if (visualNextNode == null) {
-					visualContainer.appendChild(visualNewNode);
-				} else {
-					visualContainer.insertBefore(visualNewNode, visualNextNode);
+			if (elementMapping != null) {
+				nsIDOMNode visualNewNode = elementMapping.getVisualNode();
+				if (visualNewNode != null) {
+					/*
+					 * https://jira.jboss.org/jira/browse/JBIDE-3373 Do not add
+					 * additional visual node for f:facet when it is inserted into
+					 * existing one.
+					 */
+					nsIDOMElement element = null;
+					try {
+						element = queryInterface(visualNewNode, nsIDOMElement.class);
+					} catch (org.mozilla.xpcom.XPCOMException e) {
+						/*
+						 * Cannot parse node to element, do nothing
+						 */
+					}
+					if (!((null != element) && element.hasAttribute(VPE_FACET))) {
+						nsIDOMNode nn = null;
+						if (visualNextNode == null) {
+							nn = visualContainer.appendChild(visualNewNode);
+						} else {
+							nn = visualContainer.insertBefore(visualNewNode, visualNextNode);
+						}
+						/*
+						 * https://issues.jboss.org/browse/JBIDE-9932
+						 * Only nodes that have been added into the DOM
+						 * should be registered via elementMapping.
+						 */
+						if (isCurrentMainDocument()) {
+							elementMapping.setVisualNode(nn);
+							registerNodes(elementMapping);
+						}
+						
+					}
+					return true;
 				}
 			}
-			return true;
-		}
-		} catch(XPCOMException xpcomException) {
+		} catch (XPCOMException xpcomException) {
 			VpePlugin.reportProblem(xpcomException);
 		}
-
 		return false;
 	}
 
@@ -316,10 +324,7 @@
 	 * @param visualOldContainer visual node, in which the caller plans to insert new visual node 
 	 * @return new visual node
 	 */
-	public nsIDOMNode createNode(Node sourceNode,
-			nsIDOMNode visualOldContainer) throws VpeDisposeException {
-
-		boolean registerFlag = isCurrentMainDocument();
+	public VpeElementMapping createNode(Node sourceNode, nsIDOMNode visualOldContainer) throws VpeDisposeException {
 		//it's check for initialization visualController,
 		//if we trying to process some event when controller
 		//hasn't been initialized, it's causes 
@@ -444,7 +449,8 @@
 				&& visualNewNode.getNodeType() == nsIDOMNode.ELEMENT_NODE) {
 			setTooltip((Element) sourceNode, queryInterface(visualNewNode, nsIDOMElement.class));
 		}
-		if (registerFlag) {
+		VpeElementMapping elementMapping = null;
+		if (isCurrentMainDocument()) {
 			final VpeElementData data = creationData.getElementData();
 			if ((sourceNodeProxy != null) && (data != null)
 					&& (data.getNodesData() != null)
@@ -453,8 +459,8 @@
 					if (nodeData.getSourceNode() != null) {
 						Node attr = null;
 						if(sourceNode.getAttributes()!=null) {
-							attr =	sourceNode.getAttributes().getNamedItem(nodeData
-								.getSourceNode().getNodeName());
+							attr = sourceNode.getAttributes().getNamedItem(
+									nodeData.getSourceNode().getNodeName());
 						} else {
 							//Text node haven't child nodes, but it's  node.
 							attr = sourceNode;
@@ -463,9 +469,8 @@
 						nodeData.setEditable(false);
 					}
 				}
-
 			}
-			VpeElementMapping elementMapping = new VpeElementMapping(
+			elementMapping = new VpeElementMapping(
 					sourceNode, visualNewNode, template,
 					ifDependencySet, creationData.getData(), data);
 			registerNodes(elementMapping);
@@ -511,7 +516,17 @@
 			VpePlugin.getPluginLog().logError(ex);
 		}
 		getPageContext().setCurrentVisualNode(null);
-		return visualNewNode;
+		/*
+		 * https://issues.jboss.org/browse/JBIDE-9932
+		 * Create "fake" mapping for the node that will not
+		 * be registered. 
+		 */
+		if (elementMapping == null) {
+			elementMapping = new VpeElementMapping(
+					sourceNode, visualNewNode, template,
+					ifDependencySet, creationData.getData(), null);
+		}
+		return elementMapping;
 	}
 
 	protected void correctVisualAttribute(nsIDOMElement element) {
@@ -544,22 +559,19 @@
 	 * @param sourceContainer
 	 * @param visualContainer
 	 */
-	protected void addChildren(VpeTemplate containerTemplate,
-			Node sourceContainer, nsIDOMNode visualContainer) {
+	protected void addChildren(VpeTemplate containerTemplate, Node sourceContainer, nsIDOMNode visualContainer) {
 		NodeList sourceNodes = sourceContainer.getChildNodes();
 		int len = sourceNodes.getLength();
 		int childrenCount = 0;
 		for (int i = 0; i < len; i++) {
 			Node sourceNode = sourceNodes.item(i);
 			if (addNode(sourceNode, null, visualContainer)) {
-				if (Node.ELEMENT_NODE == sourceNode.getNodeType()) {
-				}
+//				if (Node.ELEMENT_NODE == sourceNode.getNodeType()) { }
 				childrenCount++;
 			}
 		}
 		if (childrenCount == 0) {
-			setPseudoContent(containerTemplate, sourceContainer,
-					visualContainer);
+			setPseudoContent(containerTemplate, sourceContainer,visualContainer);
 		}
 	}
 
Index: src/org/jboss/tools/vpe/editor/mapping/VpeElementMapping.java
===================================================================
--- src/org/jboss/tools/vpe/editor/mapping/VpeElementMapping.java	(revision 36765)
+++ src/org/jboss/tools/vpe/editor/mapping/VpeElementMapping.java	(working copy)
@@ -93,4 +93,12 @@
 	public void setElementData(VpeElementData elementData) {
 		this.elementData = elementData;
 	}
+	
+	/**
+	 * Fix for https://issues.jboss.org/browse/JBIDE-9932
+	 * @param visualNode the visual node
+	 */
+	public void setVisualNode(nsIDOMNode visualNode) {
+		this.visualNode = visualNode;
+	}
 }
Index: src/org/jboss/tools/vpe/editor/VpePreviewDomBuilder.java
===================================================================
--- src/org/jboss/tools/vpe/editor/VpePreviewDomBuilder.java	(revision 36765)
+++ src/org/jboss/tools/vpe/editor/VpePreviewDomBuilder.java	(working copy)
@@ -20,6 +20,7 @@
 import org.jboss.tools.vpe.VpePlugin;
 import org.jboss.tools.vpe.editor.context.VpePageContext;
 import org.jboss.tools.vpe.editor.mapping.VpeDomMapping;
+import org.jboss.tools.vpe.editor.mapping.VpeElementMapping;
 import org.jboss.tools.vpe.editor.mozilla.MozillaEditor;
 import org.jboss.tools.vpe.editor.proxy.VpeProxyUtil;
 import org.jboss.tools.vpe.editor.template.VpeCreationData;
@@ -56,10 +57,8 @@
 	 * @return
 	 */
 	@Override
-	public nsIDOMNode createNode(Node sourceNode, nsIDOMNode visualOldContainer) {
-
+	public VpeElementMapping createNode(Node sourceNode, nsIDOMNode visualOldContainer) {
 			Set<?> ifDependencySet = new HashSet();
-			
 		    if(sourceNode==null||(
 		    		sourceNode.getNodeType()!=Node.TEXT_NODE
 		    		&&sourceNode.getNodeType()!=Node.ELEMENT_NODE
@@ -84,10 +83,8 @@
     					} catch(ClassCastException ex) {
     						VpePlugin.reportProblem(ex);
     						//then we create template without using proxy
-    						creationData = template.create(getPageContext(), sourceNode,
-    								getVisualDocument());
+    						creationData = template.create(getPageContext(), sourceNode,getVisualDocument());
     					}
-                
 		          } else {
                     creationData = template.create(getPageContext(), sourceNode, getVisualDocument());
                 }
@@ -123,8 +120,13 @@
 			getPageContext().setCurrentVisualNode(visualOldContainer);
 			template.validate(getPageContext(), sourceNode, getVisualDocument(), creationData);
 			getPageContext().setCurrentVisualNode(null);
-			
-			return visualNewNode;
+			/*
+			 * https://issues.jboss.org/browse/JBIDE-9932
+			 * Return VpeElementMapping instead of node itself.
+			 */
+			return new VpeElementMapping(
+					sourceNode, visualNewNode, template,
+					ifDependencySet, creationData.getData(), null); 
 	}
 
 }
