Author: nbelaevski
Date: 2009-06-03 20:38:38 -0400 (Wed, 03 Jun 2009)
New Revision: 14470
Added:
branches/community/3.3.X/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/vcp/FWriteAsScript.java
Modified:
branches/community/3.3.X/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/A4JRendererElementsFactory.java
branches/community/3.3.X/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/std/ScriptObjectTemplateElement.java
Log:
https://jira.jboss.org/jira/browse/RF-7247
Modified:
branches/community/3.3.X/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/A4JRendererElementsFactory.java
===================================================================
---
branches/community/3.3.X/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/A4JRendererElementsFactory.java 2009-06-04
00:06:54 UTC (rev 14469)
+++
branches/community/3.3.X/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/A4JRendererElementsFactory.java 2009-06-04
00:38:38 UTC (rev 14470)
@@ -38,6 +38,7 @@
import org.ajax4jsf.templatecompiler.elements.std.SetTemplateElement;
import org.ajax4jsf.templatecompiler.elements.vcp.AjaxRenderedAreaElement;
import org.ajax4jsf.templatecompiler.elements.vcp.FClientIDTemplateElement;
+import org.ajax4jsf.templatecompiler.elements.vcp.FWriteAsScript;
import org.ajax4jsf.templatecompiler.elements.vcp.HeaderScriptsElement;
import org.ajax4jsf.templatecompiler.elements.vcp.HeaderStylesElement;
import org.apache.commons.logging.Log;
@@ -76,6 +77,7 @@
mapClasses.put("c:forEach", ForEachTemplateElement.class.getName());
mapClasses.put("f:clientid", FClientIDTemplateElement.class.getName());
mapClasses.put("f:clientId", FClientIDTemplateElement.class.getName());
+ mapClasses.put("f:writeAsScript", FWriteAsScript.class.getName());
mapClasses.put("f:insertComponent",
"org.ajax4jsf.templatecompiler.elements.vcp.InsertComponent");
Modified:
branches/community/3.3.X/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/std/ScriptObjectTemplateElement.java
===================================================================
---
branches/community/3.3.X/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/std/ScriptObjectTemplateElement.java 2009-06-04
00:06:54 UTC (rev 14469)
+++
branches/community/3.3.X/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/std/ScriptObjectTemplateElement.java 2009-06-04
00:38:38 UTC (rev 14470)
@@ -51,12 +51,18 @@
super(element, componentBean);
NamedNodeMap nnm = element.getAttributes();
- variableName = nnm.getNamedItem("var").getNodeValue();
- if (variableName == null || variableName.length() == 0) {
+ Node varNode = nnm.getNamedItem("var");
+ if (varNode == null) {
throw new RuntimeException("'var' attribute required for c:scriptObject
tag!");
}
- this.getComponentBean().addVariable(variableName, VARIABLE_TYPE);
+ variableName = varNode.getNodeValue();
+
+ try {
+ this.getComponentBean().addVariable(variableName, VARIABLE_TYPE.getName());
+ } catch (CompilationException e) {
+ throw new RuntimeException(e.getMessage(), e);
+ }
}
private static ThreadLocal<String> variableNamesStorage = new
ThreadLocal<String>();
Added:
branches/community/3.3.X/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/vcp/FWriteAsScript.java
===================================================================
---
branches/community/3.3.X/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/vcp/FWriteAsScript.java
(rev 0)
+++
branches/community/3.3.X/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/vcp/FWriteAsScript.java 2009-06-04
00:38:38 UTC (rev 14470)
@@ -0,0 +1,56 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+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.TemplateElementBase;
+import org.w3c.dom.Node;
+
+/**
+ * @author Nick Belaevski
+ * @since 3.3.2
+ */
+public class FWriteAsScript extends TemplateElementBase {
+
+ private String value;
+
+ public FWriteAsScript(Node element, CompilationContext componentBean) {
+ super(element, componentBean);
+
+ Node node = element.getAttributes().getNamedItem("value");
+ if (node == null) {
+ throw new RuntimeException("'value' attribute is required for
f:writeAsScript tag!");
+ }
+
+ value = ELParser.compileEL(node.getNodeValue(), componentBean);
+ }
+
+ public String getBeginElement() throws CompilationException {
+ return String.format("org.ajax4jsf.javascript.ScriptUtils.writeToStream(writer,
%s);\n", value);
+ }
+
+ public String getEndElement() throws CompilationException {
+ return null;
+ }
+}