You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by gp...@apache.org on 2010/09/16 16:14:29 UTC
svn commit: r997757 - in
/myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf12/src/main:
java/org/apache/myfaces/examples/codi/jsf12/scripting/ServerSideScriptingBean.java
webapp/scripting.jsp
Author: gpetracek
Date: Thu Sep 16 14:14:28 2010
New Revision: 997757
URL: http://svn.apache.org/viewvc?rev=997757&view=rev
Log:
updated example
Modified:
myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf12/src/main/java/org/apache/myfaces/examples/codi/jsf12/scripting/ServerSideScriptingBean.java
myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf12/src/main/webapp/scripting.jsp
Modified: myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf12/src/main/java/org/apache/myfaces/examples/codi/jsf12/scripting/ServerSideScriptingBean.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf12/src/main/java/org/apache/myfaces/examples/codi/jsf12/scripting/ServerSideScriptingBean.java?rev=997757&r1=997756&r2=997757&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf12/src/main/java/org/apache/myfaces/examples/codi/jsf12/scripting/ServerSideScriptingBean.java (original)
+++ myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf12/src/main/java/org/apache/myfaces/examples/codi/jsf12/scripting/ServerSideScriptingBean.java Thu Sep 16 14:14:28 2010
@@ -20,6 +20,7 @@ package org.apache.myfaces.examples.codi
import org.apache.myfaces.extensions.cdi.scripting.api.ScriptLanguage;
import org.apache.myfaces.extensions.cdi.scripting.api.ScriptExecutor;
+import org.apache.myfaces.extensions.cdi.scripting.api.ScriptBuilder;
import org.apache.myfaces.extensions.cdi.scripting.api.language.JavaScript;
import javax.enterprise.context.RequestScoped;
@@ -42,6 +43,10 @@ public class ServerSideScriptingBean
@ScriptLanguage(JavaScript.class)
private ScriptExecutor scriptExecutor;
+ @Inject
+ @ScriptLanguage(JavaScript.class)
+ private ScriptBuilder scriptBuilder;
+
//or manually
@Inject
@ScriptLanguage(JavaScript.class)
@@ -50,22 +55,29 @@ public class ServerSideScriptingBean
Double result1;
Double result2;
Double result3;
+ Double manualResult;
@PostConstruct
protected void init()
{
- result1 = this.scriptExecutor.eval("10 + 4", Double.class);
+ this.result1 = this.scriptExecutor.eval("10 + 4", Double.class);
Map<String, Object> arguments = new HashMap<String, Object>();
arguments.put("a", 10);
arguments.put("b", 4);
- result2 = this.scriptExecutor.eval("a + b", arguments, Double.class);
+ this.result2 = this.scriptExecutor.eval("a + b", arguments, Double.class);
+
+ this.result3 = this.scriptBuilder
+ .script("x + y")
+ .namedArgument("x", 3)
+ .namedArgument("y", 4)
+ .eval(Double.class);
//or manually
try
{
- result3 = (Double)this.scriptEngine.eval("3 + 4");
+ manualResult = (Double)this.scriptEngine.eval("3 + 4");
}
catch (ScriptException e)
{
@@ -87,4 +99,9 @@ public class ServerSideScriptingBean
{
return result3;
}
+
+ public Double getManualResult()
+ {
+ return manualResult;
+ }
}
Modified: myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf12/src/main/webapp/scripting.jsp
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf12/src/main/webapp/scripting.jsp?rev=997757&r1=997756&r2=997757&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf12/src/main/webapp/scripting.jsp (original)
+++ myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf12/src/main/webapp/scripting.jsp Thu Sep 16 14:14:28 2010
@@ -25,9 +25,10 @@
<f:view>
<h1>Scripting-Demo</h1>
<h:panelGrid>
- <h:outputText value="result1: #{serverSideScriptingBean.result1}"/>
- <h:outputText value="result2: #{serverSideScriptingBean.result2}"/>
- <h:outputText value="result3: #{serverSideScriptingBean.result3}"/>
+ <h:outputText value="result via injected ScriptExecutor: #{serverSideScriptingBean.result1}"/>
+ <h:outputText value="result via injected ScriptExecutor (parameterized script): #{serverSideScriptingBean.result2}"/>
+ <h:outputText value="result via injected ScriptBuilder (parameterized script): #{serverSideScriptingBean.result3}"/>
+ <h:outputText value="result via injected ScriptEngine: #{serverSideScriptingBean.manualResult}"/>
<h:outputText value="inline: #{sExec.js['2 * 7']}"/>
</h:panelGrid>
</f:view>