### Eclipse Workspace Patch 1.0
#P org.jboss.tools.vpe
Index: src/org/jboss/tools/vpe/editor/template/VpeRenderingTemplate.java
===================================================================
--- src/org/jboss/tools/vpe/editor/template/VpeRenderingTemplate.java	(revision 36864)
+++ src/org/jboss/tools/vpe/editor/template/VpeRenderingTemplate.java	(working copy)
@@ -41,14 +41,11 @@
 		return  new VpeCreationData(null);
 	}
 
-	/* (non-Javadoc)
-	 * @see org.jboss.tools.vpe.editor.template.VpeAbstractTemplate#getNodeForUpdate(org.jboss.tools.vpe.editor.context.VpePageContext, org.w3c.dom.Node, org.mozilla.interfaces.nsIDOMNode, java.lang.Object)
-	 */
 	@Override
 	public Node getNodeForUpdate(VpePageContext pageContext, Node sourceNode,
 			nsIDOMNode visualNode, Object data) {
 		//if rendered=false, template hasn't visual presentations
-		//so we should upadte parent node
+		//so we should update parent node
 		return sourceNode.getParentNode();
 	}
 }
Index: src/org/jboss/tools/vpe/editor/VpeDomBuilder.java
===================================================================
--- src/org/jboss/tools/vpe/editor/VpeDomBuilder.java	(revision 36864)
+++ src/org/jboss/tools/vpe/editor/VpeDomBuilder.java	(working copy)
@@ -44,11 +44,8 @@
 		if (sorceAdapter == null) {
 			return;
 		}
-		
 		domMapping.mapNodes(nodeMapping);
 		Node sourceNode = nodeMapping.getSourceNode();
-		
-		
 		/* yradtsevich:
 		 * checking for ((INodeNotifier) sourceNode).getExistingAdapter(sorceAdapter) == null
  		 * is not used because of JBIDE-8049 (JBIDE-8051)
Index: src/org/jboss/tools/vpe/editor/mapping/VpeDomMapping.java
===================================================================
--- src/org/jboss/tools/vpe/editor/mapping/VpeDomMapping.java	(revision 36864)
+++ src/org/jboss/tools/vpe/editor/mapping/VpeDomMapping.java	(working copy)
@@ -40,6 +40,16 @@
 		}
 	}
 	
+	public void remapVisualNode(nsIDOMNode visualNode, nsIDOMNode registeredVisualNewNode) {
+		if ((visualNode != null) && (registeredVisualNewNode != null)) {
+			VpeNodeMapping nodeMapping = visualMap.get(visualNode);
+			if (nodeMapping != null) {
+				nodeMapping.setVisualNode(registeredVisualNewNode);
+				visualMap.remove(visualNode);
+				visualMap.put(registeredVisualNewNode, nodeMapping);
+			}
+		}
+	}
 	public void clear(nsIDOMNode except) {
 		Set<Map.Entry<nsIDOMNode, VpeNodeMapping>> entrySet = visualMap.entrySet();
 		Iterator<Map.Entry<nsIDOMNode, VpeNodeMapping>> iter = entrySet.iterator();
@@ -72,19 +82,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 36864)
+++ 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);
-
-			
+			nsIDOMNode visualNewNode = createNode(sourceNode, visualContainer);
 // Commented as fix for JBIDE-3012.	
 //		// Fix for JBIDE-1097
 //		try {
@@ -277,35 +274,41 @@
 //		} 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 (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 registeredVisualNewNode = null;
+						if (visualNextNode == null) {
+							registeredVisualNewNode = visualContainer.appendChild(visualNewNode);
+						} else {
+							registeredVisualNewNode = visualContainer.insertBefore(visualNewNode, visualNextNode);
+						}
+						/*
+						 * https://issues.jboss.org/browse/JBIDE-9932
+						 * Update visual nodes in mapped nodes.
+						 */
+						if (isCurrentMainDocument()) {
+							domMapping.remapVisualNode(visualNewNode, registeredVisualNewNode);
+						}
+						
+					}
+					return true;
 				}
-			}
-			return true;
-		}
-		} catch(XPCOMException xpcomException) {
+		} catch (XPCOMException xpcomException) {
 			VpePlugin.reportProblem(xpcomException);
 		}
-
 		return false;
 	}
 
@@ -316,10 +319,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 nsIDOMNode 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 +444,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 +454,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 +464,8 @@
 						nodeData.setEditable(false);
 					}
 				}
-
 			}
-			VpeElementMapping elementMapping = new VpeElementMapping(
+			elementMapping = new VpeElementMapping(
 					sourceNode, visualNewNode, template,
 					ifDependencySet, creationData.getData(), data);
 			registerNodes(elementMapping);
@@ -552,14 +552,12 @@
 		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/VpePreviewDomBuilder.java
===================================================================
--- src/org/jboss/tools/vpe/editor/VpePreviewDomBuilder.java	(revision 36864)
+++ src/org/jboss/tools/vpe/editor/VpePreviewDomBuilder.java	(working copy)
@@ -57,9 +57,7 @@
 	 */
 	@Override
 	public nsIDOMNode createNode(Node sourceNode, nsIDOMNode visualOldContainer) {
-
 			Set<?> ifDependencySet = new HashSet();
-			
 		    if(sourceNode==null||(
 		    		sourceNode.getNodeType()!=Node.TEXT_NODE
 		    		&&sourceNode.getNodeType()!=Node.ELEMENT_NODE
@@ -74,8 +72,8 @@
 			//FIX FOR JBIDE-1568, added by Max Areshkau
 			try {
 		          if (getPageContext().getElService().isELNode(sourceNode)) {
-                    final Node sourceNodeProxy =  VpeProxyUtil.createProxyForELExpressionNode(getPageContext(),
-        					sourceNode);
+                    final Node sourceNodeProxy =  VpeProxyUtil.createProxyForELExpressionNode(
+                    		getPageContext(), sourceNode);
     				try {
     					creationData = template.create(getPageContext(),
     							sourceNodeProxy, getVisualDocument());
@@ -84,10 +82,9 @@
     					} 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,7 +120,6 @@
 			getPageContext().setCurrentVisualNode(visualOldContainer);
 			template.validate(getPageContext(), sourceNode, getVisualDocument(), creationData);
 			getPageContext().setCurrentVisualNode(null);
-			
 			return visualNewNode;
 	}
 
Index: src/org/jboss/tools/vpe/editor/util/SourceDomUtil.java
===================================================================
--- src/org/jboss/tools/vpe/editor/util/SourceDomUtil.java	(revision 36864)
+++ src/org/jboss/tools/vpe/editor/util/SourceDomUtil.java	(working copy)
@@ -25,12 +25,12 @@
 import org.w3c.dom.NodeList;
 
 public class SourceDomUtil {
-	private static final Set<String> templatesNamespacesWithRendered=new HashSet<String>();
+	private static final Set<String> TEMPLATES_NAMESPACES_WITH_RENDERED=new HashSet<String>();
 	static {
-		templatesNamespacesWithRendered.add("h:"); //$NON-NLS-1$
-		templatesNamespacesWithRendered.add("a4j:"); //$NON-NLS-1$
-		templatesNamespacesWithRendered.add("rich:"); //$NON-NLS-1$
-		templatesNamespacesWithRendered.add("seam:"); //$NON-NLS-1$
+		TEMPLATES_NAMESPACES_WITH_RENDERED.add("h:"); //$NON-NLS-1$
+		TEMPLATES_NAMESPACES_WITH_RENDERED.add("a4j:"); //$NON-NLS-1$
+		TEMPLATES_NAMESPACES_WITH_RENDERED.add("rich:"); //$NON-NLS-1$
+		TEMPLATES_NAMESPACES_WITH_RENDERED.add("seam:"); //$NON-NLS-1$
 	}
 	
 	static public Node getAncestorNode(Node sourceNode, String tagName) {
@@ -77,17 +77,17 @@
 	public static boolean isRenderedAttrEqFalse(VpePageContext pageContext,
 			Element sourceNode) {
 		boolean result = false;
-		final String attrName = "rendered"; //$NON-NLS-1$
+		final String ATTR_RENDERED = "rendered"; //$NON-NLS-1$
 		Element tempElement = sourceNode;
-		if (sourceNode.hasAttribute(attrName)) {
+		if (sourceNode.hasAttribute(ATTR_RENDERED)) {
 			if (pageContext.getElService().isELNode(sourceNode)) {
 				tempElement = (Element) VpeProxyUtil
 						.createProxyForELExpressionNode(pageContext, sourceNode);
 			}
-			if ("false".equals(tempElement.getAttribute(attrName))) { //$NON-NLS-1$
+			if ("false".equals(tempElement.getAttribute(ATTR_RENDERED))) { //$NON-NLS-1$
 				String templateName = VpeTemplateManager.getInstance().getTemplateName(pageContext, sourceNode);
 				String [] templatePrefix = templateName.split(":"); //$NON-NLS-1$
-				if(templatePrefix.length>1 && templatesNamespacesWithRendered.contains(templatePrefix[0]+":")) { //$NON-NLS-1$
+				if(templatePrefix.length>1 && TEMPLATES_NAMESPACES_WITH_RENDERED.contains(templatePrefix[0]+":")) { //$NON-NLS-1$
 					result = true;
 				}
 			}
Index: src/org/jboss/tools/vpe/editor/mapping/VpeNodeMapping.java
===================================================================
--- src/org/jboss/tools/vpe/editor/mapping/VpeNodeMapping.java	(revision 36864)
+++ src/org/jboss/tools/vpe/editor/mapping/VpeNodeMapping.java	(working copy)
@@ -33,4 +33,12 @@
 	public nsIDOMNode getVisualNode() {
 		return visualNode;
 	}
+	
+	/**
+	 * Fix for https://issues.jboss.org/browse/JBIDE-9932
+	 * @param visualNode the visual node
+	 */
+	public void setVisualNode(nsIDOMNode visualNode) {
+		this.visualNode = visualNode;
+	}
 }
#P org.jboss.tools.vpe.base.test
Index: src/org/jboss/tools/vpe/base/test/VpeTest.java
===================================================================
--- src/org/jboss/tools/vpe/base/test/VpeTest.java	(revision 36864)
+++ src/org/jboss/tools/vpe/base/test/VpeTest.java	(working copy)
@@ -11,6 +11,8 @@
 
 package org.jboss.tools.vpe.base.test;
 
+import static org.jboss.tools.vpe.xulrunner.util.XPCOM.queryInterface;
+
 import java.io.IOException;
 import java.util.Collection;
 import java.util.Map;
@@ -428,18 +430,24 @@
 	 * @param elementId
 	 * @return
 	 */
-	protected nsIDOMElement findElementById(VpeController controller,
-			String elementId) {
-
+	protected nsIDOMElement findElementById(VpeController controller,String elementId) {
 		Element sourceElement = findSourceElementById(controller, elementId);
-
-		VpeNodeMapping nodeMapping = controller.getDomMapping().getNodeMapping(
-				sourceElement);
-
-		if (nodeMapping == null)
-			return null;
-
-		return (nsIDOMElement) nodeMapping.getVisualNode();
+		nsIDOMElement element = null;
+		VpeNodeMapping nodeMapping = controller
+				.getDomMapping().getNodeMapping(sourceElement);
+		if (nodeMapping != null) {
+			nsIDOMNode node = nodeMapping.getVisualNode();
+			if (node != null) {
+				try {
+					element = queryInterface(node, nsIDOMElement.class);
+				} catch (org.mozilla.xpcom.XPCOMException e) { 
+					//Do nothing
+				} catch (NullPointerException e) { 
+					//Do nothing					
+				}
+			}
+		}
+		return element; 
 	}
 	
 	protected String getEditorID(){
Index: src/org/jboss/tools/vpe/base/test/ComponentContentTest.java
===================================================================
--- src/org/jboss/tools/vpe/base/test/ComponentContentTest.java	(revision 36864)
+++ src/org/jboss/tools/vpe/base/test/ComponentContentTest.java	(working copy)
@@ -133,7 +133,7 @@
 				throws DOMComparisonException {
 		// get element by id
 		nsIDOMElement vpeElement = findElementById(controller, elementId);
-		assertNotNull("Cann't find element with id="+elementId,vpeElement); //$NON-NLS-1$
+		assertNotNull("Cannot find element with id="+elementId,vpeElement); //$NON-NLS-1$
 
 		// DOMTreeDumper dumper = new DOMTreeDumper(
 		// VpeDebug.VISUAL_DUMP_PRINT_HASH);
