Author: maksimkaszynski
Date: 2007-07-27 09:26:56 -0400 (Fri, 27 Jul 2007)
New Revision: 1890
Added:
trunk/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/vcp/AjaxRenderedAreaElement.java
trunk/cdk/generator/src/main/resources/META-INF/templates/templatecompiler/ajaxRenderedArea.vm
Modified:
trunk/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/A4JRendererElementsFactory.java
Log:
added ajaxrendered area tag
Modified:
trunk/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/A4JRendererElementsFactory.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/A4JRendererElementsFactory.java 2007-07-27
13:00:13 UTC (rev 1889)
+++
trunk/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/A4JRendererElementsFactory.java 2007-07-27
13:26:56 UTC (rev 1890)
@@ -30,6 +30,7 @@
import org.ajax4jsf.templatecompiler.elements.html.CommentElement;
import org.ajax4jsf.templatecompiler.elements.html.PIElement;
import org.ajax4jsf.templatecompiler.elements.html.TextElement;
+import org.ajax4jsf.templatecompiler.elements.vcp.AjaxRenderedAreaElement;
import org.ajax4jsf.templatecompiler.elements.vcp.HeaderScriptsElement;
import org.ajax4jsf.templatecompiler.elements.vcp.HeaderStylesElement;
import org.w3c.dom.Node;
@@ -102,6 +103,7 @@
mapClasses.put("f:template", RootElement.class.getName());
mapClasses.put("f:root", RootElement.class.getName());
mapClasses.put("jsp:root", RootElement.class.getName());
+ mapClasses.put("ajax:update", AjaxRenderedAreaElement.class.getName());
}
/* (non-Javadoc)
Added:
trunk/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/vcp/AjaxRenderedAreaElement.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/vcp/AjaxRenderedAreaElement.java
(rev 0)
+++
trunk/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/vcp/AjaxRenderedAreaElement.java 2007-07-27
13:26:56 UTC (rev 1890)
@@ -0,0 +1,60 @@
+/**
+ *
+ */
+package org.ajax4jsf.templatecompiler.elements.vcp;
+
+import org.ajax4jsf.templatecompiler.builder.CompilationContext;
+import org.ajax4jsf.templatecompiler.builder.CompilationException;
+import org.ajax4jsf.templatecompiler.el.ELParser;
+import org.ajax4jsf.templatecompiler.elements.A4JRendererElementsFactory;
+import org.ajax4jsf.templatecompiler.elements.TemplateElementBase;
+import org.apache.velocity.VelocityContext;
+import org.w3c.dom.Node;
+
+/**
+ * Add comma separated list of ids to Ajax Context's rendered areas collection.
+ * @author Maksim Kaszynski
+ *
+ */
+public class AjaxRenderedAreaElement extends TemplateElementBase {
+
+ private static final String TEMPLATE =
A4JRendererElementsFactory.TEMPLATES_TEMPLATECOMPILER_PATH+"/ajaxRenderedArea.vm";
+
+ private String values;
+
+ public AjaxRenderedAreaElement(Node element,
+ CompilationContext componentBean) {
+ super(element, componentBean);
+ values = ELParser.compileEL(element.getTextContent(), this.getComponentBean());
+ componentBean.addToImport("org.ajax4jsf.context.AjaxContext");
+ }
+
+ /* (non-Javadoc)
+ * @see org.ajax4jsf.templatecompiler.elements.TemplateElement#getBeginElement()
+ */
+ public String getBeginElement() throws CompilationException {
+
+ VelocityContext context = new VelocityContext();
+ context.put("areas", this.values);
+ return this.getComponentBean().processTemplate(getTemplateName(), context);
+ }
+
+ /* (non-Javadoc)
+ * @see org.ajax4jsf.templatecompiler.elements.TemplateElement#getEndElement()
+ */
+ public String getEndElement() throws CompilationException {
+
+ return null;
+ }
+
+ protected String getTemplateName() {
+ return TEMPLATE;
+ }
+
+ @Override
+ public boolean isSkipBody() {
+ // TODO Auto-generated method stub
+ return true;
+ }
+
+}
Added:
trunk/cdk/generator/src/main/resources/META-INF/templates/templatecompiler/ajaxRenderedArea.vm
===================================================================
---
trunk/cdk/generator/src/main/resources/META-INF/templates/templatecompiler/ajaxRenderedArea.vm
(rev 0)
+++
trunk/cdk/generator/src/main/resources/META-INF/templates/templatecompiler/ajaxRenderedArea.vm 2007-07-27
13:26:56 UTC (rev 1890)
@@ -0,0 +1,13 @@
+#if($areas)
+ {
+ //Auto-generated block.
+ //Add to ajax context list of element ids passed as *areas* param
+ String [] _areas = (${areas}).split(",\" ");
+ AjaxContext _ajaxContext = AjaxContext.getCurrentInstance(context);
+ if (_ajaxContext.isAjaxRequest()) {
+ for (int _i = 0; _i < _areas.length; _i++) {
+ _ajaxContext.addRenderedArea(_areas[_i]);
+ }
+ }
+ }
+#end
\ No newline at end of file