Author: yradtsevich
Date: 2009-02-04 10:42:56 -0500 (Wed, 04 Feb 2009)
New Revision: 13468
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.ajax4jsf/src/org/jboss/tools/jsf/vpe/ajax4jsf/template/Ajax4JSFPageTemplate.java
trunk/jsf/tests/org.jboss.tools.jsf.vpe.ajax4jsf.test/resources/ajax4jsfTests/WebContent/pages/components/page.xhtml
trunk/jsf/tests/org.jboss.tools.jsf.vpe.ajax4jsf.test/resources/ajax4jsfTests/WebContent/pages/components/page.xhtml.xml
trunk/jsf/tests/org.jboss.tools.jsf.vpe.ajax4jsf.test/src/org/jboss/tools/jsf/vpe/ajax4jsf/test/Ajax4JsfComponentContentTest.java
Log:
RESOLVED - issue JBIDE-3718: a4j:page isn't rendered facets correctly
https://jira.jboss.org/jira/browse/JBIDE-3718
- the template of a4j:page has been almost completely rewritten
- JUnit test has been modified
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.ajax4jsf/src/org/jboss/tools/jsf/vpe/ajax4jsf/template/Ajax4JSFPageTemplate.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.ajax4jsf/src/org/jboss/tools/jsf/vpe/ajax4jsf/template/Ajax4JSFPageTemplate.java 2009-02-04
15:42:09 UTC (rev 13467)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.ajax4jsf/src/org/jboss/tools/jsf/vpe/ajax4jsf/template/Ajax4JSFPageTemplate.java 2009-02-04
15:42:56 UTC (rev 13468)
@@ -1,64 +1,94 @@
/*******************************************************************************
- * Copyright (c) 2007-2008 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is made available under the terms of the
- * Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at
http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributor:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
+ * Copyright (c) 2007-2008 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
package org.jboss.tools.jsf.vpe.ajax4jsf.template;
-import org.jboss.tools.jsf.vpe.richfaces.ComponentUtil;
import org.jboss.tools.vpe.editor.context.VpePageContext;
import org.jboss.tools.vpe.editor.template.VpeAbstractTemplate;
import org.jboss.tools.vpe.editor.template.VpeChildrenInfo;
import org.jboss.tools.vpe.editor.template.VpeCreationData;
+import org.jboss.tools.vpe.editor.template.VpeTemplateManager;
import org.jboss.tools.vpe.editor.util.HTML;
import org.mozilla.interfaces.nsIDOMDocument;
import org.mozilla.interfaces.nsIDOMElement;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+/**
+ * The template intended for processing {@code <a4j:page>} elements.
+ *
+ * @author dmaliarevich
+ * @author yradtsevich
+ */
public class Ajax4JSFPageTemplate extends VpeAbstractTemplate {
- private static final String HEAD_FACET_NAME = "head"; //$NON-NLS-1$
+ private static final String FACET_TEMPLATE_NAME = "f:facet"; //$NON-NLS-1$
+ private static final String ATTR_NAME = "name"; //$NON-NLS-1$
+ private static final String HEAD_FACET_NAME = "head"; //$NON-NLS-1$
- public VpeCreationData create(VpePageContext pageContext, Node sourceNode,
- nsIDOMDocument visualDocument) {
- Element sourceElement = (Element) sourceNode;
- nsIDOMElement divHtml = visualDocument.createElement(HTML.TAG_DIV);
- nsIDOMElement divHead = visualDocument.createElement(HTML.TAG_DIV);
- nsIDOMElement divBody = visualDocument.createElement(HTML.TAG_DIV);
- VpeCreationData creationData = new VpeCreationData(divHtml);
+ public VpeCreationData create(VpePageContext pageContext, Node sourceNode,
+ nsIDOMDocument visualDocument) {
+ Element sourceElement = (Element) sourceNode;
- /*
- * Encoding label value
+ nsIDOMElement bodyContainer = visualDocument.createElement(HTML.TAG_DIV);
+ VpeCreationData creationData = new VpeCreationData(bodyContainer);
+
+ // Mozilla renders HEAD nested in HEAD pretty well, so we are nesting these elements
+ nsIDOMElement headContainer = visualDocument.createElement(HTML.TAG_HEAD);
+ pageContext.getVisualBuilder().getHeadNode().appendChild(headContainer);
+
+ VpeChildrenInfo headChildrenInfo = new VpeChildrenInfo(headContainer);
+ creationData.addChildrenInfo(headChildrenInfo);
+
+ VpeChildrenInfo bodyChildrenInfo = new VpeChildrenInfo(bodyContainer);
+ creationData.addChildrenInfo(bodyChildrenInfo);
+
+ NodeList childNodes = sourceElement.getChildNodes();
+ for (int i = 0; i < childNodes.getLength(); i++) {
+ Node child = childNodes.item(i);
+
+ if (isHeadFacet(pageContext, child)) {
+ Element headFacet = (Element) child;
+
+ NodeList headFacetChildren = headFacet.getChildNodes();
+ for (int j = 0; j < headFacetChildren.getLength(); j++) {
+ headChildrenInfo.addSourceChild(headFacetChildren.item(j));
+ }
+ } else {
+ bodyChildrenInfo.addSourceChild(child);
+ }
+ }
+
+ return creationData;
+ }
+
+ /**
+ * Returns {@code true} if and only if the {@code node} is a head facet.
*/
- Element headFacet = ComponentUtil.getFacet(sourceElement,
- HEAD_FACET_NAME);
- if (null != headFacet) {
- VpeChildrenInfo childrenInfo = new VpeChildrenInfo(divHead);
- childrenInfo.addSourceChild(headFacet);
- divHtml.appendChild(divHead);
- creationData.addChildrenInfo(childrenInfo);
+ private static boolean isHeadFacet(VpePageContext pageContext, Node node) {
+ String templateName = VpeTemplateManager.getInstance().getTemplateName(pageContext,
node);
+ if (FACET_TEMPLATE_NAME.equals(templateName)) {
+ Element element = (Element) node;
+ String name = element.getAttribute(ATTR_NAME);
+ if (HEAD_FACET_NAME.equals(name)) {
+ return true;
+ }
+ }
+ return false;
}
- VpeChildrenInfo divBodyInfo = new VpeChildrenInfo(divBody);
- creationData.addChildrenInfo(divBodyInfo);
- divHtml.appendChild(divBody);
- for (Node child : ComponentUtil.getChildren(sourceElement, true)) {
- divBodyInfo.addSourceChild(child);
+ @Override
+ public boolean isRecreateAtAttrChange(VpePageContext pageContext,
+ Element sourceElement, nsIDOMDocument visualDocument,
+ nsIDOMElement visualNode, Object data, String name, String value) {
+ return true;
}
-
- return creationData;
- }
-
- public boolean isRecreateAtAttrChange(VpePageContext pageContext,
- Element sourceElement, nsIDOMDocument visualDocument,
- nsIDOMElement visualNode, Object data, String name, String value) {
- return true;
- }
-
}
Modified:
trunk/jsf/tests/org.jboss.tools.jsf.vpe.ajax4jsf.test/resources/ajax4jsfTests/WebContent/pages/components/page.xhtml
===================================================================
(Binary files differ)
Modified:
trunk/jsf/tests/org.jboss.tools.jsf.vpe.ajax4jsf.test/resources/ajax4jsfTests/WebContent/pages/components/page.xhtml.xml
===================================================================
---
trunk/jsf/tests/org.jboss.tools.jsf.vpe.ajax4jsf.test/resources/ajax4jsfTests/WebContent/pages/components/page.xhtml.xml 2009-02-04
15:42:09 UTC (rev 13467)
+++
trunk/jsf/tests/org.jboss.tools.jsf.vpe.ajax4jsf.test/resources/ajax4jsfTests/WebContent/pages/components/page.xhtml.xml 2009-02-04
15:42:56 UTC (rev 13468)
@@ -1,5 +1,11 @@
<tests>
<test id="page">
-
+ <DIV>
+ <SPAN CLASS="red">
+ <SPAN CLASS="vpe-text">
+ Red Text
+ </SPAN>
+ </SPAN>
+ </DIV>
</test>
</tests>
\ No newline at end of file
Modified:
trunk/jsf/tests/org.jboss.tools.jsf.vpe.ajax4jsf.test/src/org/jboss/tools/jsf/vpe/ajax4jsf/test/Ajax4JsfComponentContentTest.java
===================================================================
---
trunk/jsf/tests/org.jboss.tools.jsf.vpe.ajax4jsf.test/src/org/jboss/tools/jsf/vpe/ajax4jsf/test/Ajax4JsfComponentContentTest.java 2009-02-04
15:42:09 UTC (rev 13467)
+++
trunk/jsf/tests/org.jboss.tools.jsf.vpe.ajax4jsf.test/src/org/jboss/tools/jsf/vpe/ajax4jsf/test/Ajax4JsfComponentContentTest.java 2009-02-04
15:42:56 UTC (rev 13468)
@@ -70,7 +70,7 @@
public void testOutputPanel() throws Throwable {
}
- public void _testPage() throws Throwable {
+ public void testPage() throws Throwable {
performContentTest("components/page.xhtml");//$NON-NLS-1$
}