You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by we...@apache.org on 2012/03/19 14:12:30 UTC
svn commit: r1302416 - in
/myfaces/extensions/scripting/trunk/extscript-examples/blog-example/src/main/webapp:
./ WEB-INF/ WEB-INF/groovy/ WEB-INF/groovy/groovyblog/ WEB-INF/java/blog/
Author: werpu
Date: Mon Mar 19 13:12:30 2012
New Revision: 1302416
URL: http://svn.apache.org/viewvc?rev=1302416&view=rev
Log:
https://issues.apache.org/jira/browse/EXTSCRIPT-157 adding a blogging example as standalone webapp
Added:
myfaces/extensions/scripting/trunk/extscript-examples/blog-example/src/main/webapp/WEB-INF/groovy/
myfaces/extensions/scripting/trunk/extscript-examples/blog-example/src/main/webapp/WEB-INF/groovy/groovyblog/
myfaces/extensions/scripting/trunk/extscript-examples/blog-example/src/main/webapp/WEB-INF/groovy/groovyblog/Blog.groovy
myfaces/extensions/scripting/trunk/extscript-examples/blog-example/src/main/webapp/WEB-INF/groovy/groovyblog/BlogEntry.groovy
myfaces/extensions/scripting/trunk/extscript-examples/blog-example/src/main/webapp/WEB-INF/groovy/groovyblog/BlogService.groovy
myfaces/extensions/scripting/trunk/extscript-examples/blog-example/src/main/webapp/WEB-INF/groovy/groovyblog/BlogService2.groovy
myfaces/extensions/scripting/trunk/extscript-examples/blog-example/src/main/webapp/WEB-INF/groovy/groovyblog/JSFUtil.groovy
myfaces/extensions/scripting/trunk/extscript-examples/blog-example/src/main/webapp/blog.xhtml
Modified:
myfaces/extensions/scripting/trunk/extscript-examples/blog-example/src/main/webapp/WEB-INF/java/blog/BlogEntry.java
myfaces/extensions/scripting/trunk/extscript-examples/blog-example/src/main/webapp/WEB-INF/java/blog/BlogService.java
myfaces/extensions/scripting/trunk/extscript-examples/blog-example/src/main/webapp/WEB-INF/web.xml
myfaces/extensions/scripting/trunk/extscript-examples/blog-example/src/main/webapp/template.xhtml
Added: myfaces/extensions/scripting/trunk/extscript-examples/blog-example/src/main/webapp/WEB-INF/groovy/groovyblog/Blog.groovy
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-examples/blog-example/src/main/webapp/WEB-INF/groovy/groovyblog/Blog.groovy?rev=1302416&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-examples/blog-example/src/main/webapp/WEB-INF/groovy/groovyblog/Blog.groovy (added)
+++ myfaces/extensions/scripting/trunk/extscript-examples/blog-example/src/main/webapp/WEB-INF/groovy/groovyblog/Blog.groovy Mon Mar 19 13:12:30 2012
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package groovyblog
+
+import java.util.logging.Logger
+import javax.faces.bean.ManagedBean
+import javax.faces.bean.RequestScoped
+
+@ManagedBean(name = "blogView")
+@RequestScoped
+public class Blog {
+ //bug application and session scoped beans are not refreshed structurally yet
+
+ Logger log = Logger.getLogger(Blog.class.getName())
+
+ String title = "Hello to the myfaces 2.0 Groovy dynamic blogging"
+ String title1 = "You can alter the code for this small blogging application on the fly, you even can add new classes on the fly and Grooy will pick it up"
+
+ String firstName = "aaa"
+ String lastName = ""
+ String topic = ""
+
+ String content = ""
+
+ public String addEntry() {
+ log.info("adding entry");
+
+
+ def service = JSFUtil.resolveVariable("blogService")
+
+ if (service == null) {
+ log.severe("service not found")
+ } else {
+ log.info("service found")
+
+ }
+
+ BlogEntry entry = new BlogEntry()
+ //we now map it in the verbose way, the lean way would be to do direct introspection attribute mapping
+
+ entry.firstName = firstName
+ entry.lastName = lastName
+ entry.topic = topic
+ entry.content = content
+
+
+
+ service.addEntry(entry)
+
+ //we stay on the same page
+ return null;
+ }
+
+}
\ No newline at end of file
Added: myfaces/extensions/scripting/trunk/extscript-examples/blog-example/src/main/webapp/WEB-INF/groovy/groovyblog/BlogEntry.groovy
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-examples/blog-example/src/main/webapp/WEB-INF/groovy/groovyblog/BlogEntry.groovy?rev=1302416&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-examples/blog-example/src/main/webapp/WEB-INF/groovy/groovyblog/BlogEntry.groovy (added)
+++ myfaces/extensions/scripting/trunk/extscript-examples/blog-example/src/main/webapp/WEB-INF/groovy/groovyblog/BlogEntry.groovy Mon Mar 19 13:12:30 2012
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package groovyblog;
+
+/**
+ * The entry class
+ */
+public class BlogEntry
+{
+
+ String firstName = ""
+ String lastName = ""
+ String topic = ""
+ String content = ""
+
+ public String getTopic()
+ {
+ return topic;
+ }
+}
\ No newline at end of file
Added: myfaces/extensions/scripting/trunk/extscript-examples/blog-example/src/main/webapp/WEB-INF/groovy/groovyblog/BlogService.groovy
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-examples/blog-example/src/main/webapp/WEB-INF/groovy/groovyblog/BlogService.groovy?rev=1302416&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-examples/blog-example/src/main/webapp/WEB-INF/groovy/groovyblog/BlogService.groovy (added)
+++ myfaces/extensions/scripting/trunk/extscript-examples/blog-example/src/main/webapp/WEB-INF/groovy/groovyblog/BlogService.groovy Mon Mar 19 13:12:30 2012
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package groovyblog
+
+import java.util.logging.Logger
+import javax.faces.bean.ApplicationScoped
+import javax.faces.bean.ManagedBean
+
+@ManagedBean(name = "blogService")
+@ApplicationScoped
+public class BlogService {
+ List blogEntries = new ArrayList()
+
+ public java.util.List getBlogEntries() {
+ return blogEntries
+ }
+
+ public void addEntry2(BlogEntry entry) {
+ Logger log = Logger.getLogger(BlogService.class.getName())
+ log.info("Adding entry 2, topic:" + entry.topic)
+
+ blogEntries.add(entry)
+
+ log.info("blogentries size " + blogEntries.size())
+ }
+
+ public void addEntry(BlogEntry entry) {
+
+ Logger log = Logger.getLogger(BlogService.class.getName())
+ log.info("Adding entry, topic: " + entry.topic)
+ //entry.topic = "bla bla2"
+ blogEntries.add(entry)
+
+ log.info("blogentries size" + blogEntries.size())
+ }
+
+}
\ No newline at end of file
Added: myfaces/extensions/scripting/trunk/extscript-examples/blog-example/src/main/webapp/WEB-INF/groovy/groovyblog/BlogService2.groovy
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-examples/blog-example/src/main/webapp/WEB-INF/groovy/groovyblog/BlogService2.groovy?rev=1302416&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-examples/blog-example/src/main/webapp/WEB-INF/groovy/groovyblog/BlogService2.groovy (added)
+++ myfaces/extensions/scripting/trunk/extscript-examples/blog-example/src/main/webapp/WEB-INF/groovy/groovyblog/BlogService2.groovy Mon Mar 19 13:12:30 2012
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package groovyblog
+
+import java.util.logging.Logger
+import javax.faces.bean.ManagedBean
+import javax.faces.bean.ApplicationScoped
+
+
+
+
+public class BlogService2 {
+ List blogEntries = new ArrayList()
+
+
+ public java.util.List getBlogEntries() {
+ return blogEntries
+ }
+
+ public void addEntry(def entry) {
+ Logger log = Logger.getLogger(BlogService.class.getName())
+ log.info("Adding entry, topic: " + entry.topic)
+ entry.topic = "topic from blogservice 2"
+ blogEntries.add(entry)
+
+ log.info("blogentries size" + blogEntries.size())
+ }
+
+}
\ No newline at end of file
Added: myfaces/extensions/scripting/trunk/extscript-examples/blog-example/src/main/webapp/WEB-INF/groovy/groovyblog/JSFUtil.groovy
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-examples/blog-example/src/main/webapp/WEB-INF/groovy/groovyblog/JSFUtil.groovy?rev=1302416&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-examples/blog-example/src/main/webapp/WEB-INF/groovy/groovyblog/JSFUtil.groovy (added)
+++ myfaces/extensions/scripting/trunk/extscript-examples/blog-example/src/main/webapp/WEB-INF/groovy/groovyblog/JSFUtil.groovy Mon Mar 19 13:12:30 2012
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package groovyblog;
+
+
+import java.util.logging.Logger
+import javax.faces.context.FacesContext
+
+/**
+ * Utils class to keep the code clean and mean
+ */
+public class JSFUtil {
+
+ public static Object resolveVariable(String beanName) {
+ Logger log = Logger.getLogger(JSFUtil.class.getName())
+ log.info("ElResolver Instance:" + FacesContext.getCurrentInstance().getELContext().getELResolver().toString())
+ return FacesContext.getCurrentInstance().getELContext().getELResolver().getValue(FacesContext.getCurrentInstance().getELContext(), null, beanName)
+ }
+
+}
\ No newline at end of file
Modified: myfaces/extensions/scripting/trunk/extscript-examples/blog-example/src/main/webapp/WEB-INF/java/blog/BlogEntry.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-examples/blog-example/src/main/webapp/WEB-INF/java/blog/BlogEntry.java?rev=1302416&r1=1302415&r2=1302416&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-examples/blog-example/src/main/webapp/WEB-INF/java/blog/BlogEntry.java (original)
+++ myfaces/extensions/scripting/trunk/extscript-examples/blog-example/src/main/webapp/WEB-INF/java/blog/BlogEntry.java Mon Mar 19 13:12:30 2012
@@ -35,7 +35,7 @@ public class BlogEntry {
String content = "";
public String getFirstName() {
- return firstName+"aaa";
+ return firstName;
}
public void setFirstName(String firstName) {
Modified: myfaces/extensions/scripting/trunk/extscript-examples/blog-example/src/main/webapp/WEB-INF/java/blog/BlogService.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-examples/blog-example/src/main/webapp/WEB-INF/java/blog/BlogService.java?rev=1302416&r1=1302415&r2=1302416&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-examples/blog-example/src/main/webapp/WEB-INF/java/blog/BlogService.java (original)
+++ myfaces/extensions/scripting/trunk/extscript-examples/blog-example/src/main/webapp/WEB-INF/java/blog/BlogService.java Mon Mar 19 13:12:30 2012
@@ -34,6 +34,7 @@ public class BlogService implements Blog
List<Object> blogEntries = Collections.synchronizedList(new LinkedList<Object>());
+
/**
* Add an entry to our blogging list
* Note: we have a testing annotation,
Modified: myfaces/extensions/scripting/trunk/extscript-examples/blog-example/src/main/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-examples/blog-example/src/main/webapp/WEB-INF/web.xml?rev=1302416&r1=1302415&r2=1302416&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-examples/blog-example/src/main/webapp/WEB-INF/web.xml (original)
+++ myfaces/extensions/scripting/trunk/extscript-examples/blog-example/src/main/webapp/WEB-INF/web.xml Mon Mar 19 13:12:30 2012
@@ -18,10 +18,10 @@
* specific language governing permissions and limitations
* under the License.
-->
-<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
-
+<web-app xmlns="http://java.sun.com/xml/ns/javaee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
+ version="3.0">
<description>Webproject.xml</description>
@@ -88,19 +88,6 @@
<param-value>org.apache.myfaces.extensions.scripting.jsf.facelet.MyFacesReroutingResourceResolver</param-value>
</context-param>
- <filter>
- <filter-name>scriptingFilter</filter-name>
- <filter-class>org.apache.myfaces.extensions.scripting.core.servlet.ScriptingServletFilter</filter-class>
- </filter>
- <filter-mapping>
- <filter-name>scriptingFilter</filter-name>
- <url-pattern>/*</url-pattern>
- <dispatcher>REQUEST</dispatcher>
- <dispatcher>FORWARD</dispatcher>
- <dispatcher>INCLUDE</dispatcher>
- <dispatcher>ERROR</dispatcher>
- </filter-mapping>
-
<!--
Note, this servlet filter is vital without it Ext-Scripting will not work,
if you do not set it you will get an appropriate warning in the command line
Added: myfaces/extensions/scripting/trunk/extscript-examples/blog-example/src/main/webapp/blog.xhtml
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-examples/blog-example/src/main/webapp/blog.xhtml?rev=1302416&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-examples/blog-example/src/main/webapp/blog.xhtml (added)
+++ myfaces/extensions/scripting/trunk/extscript-examples/blog-example/src/main/webapp/blog.xhtml Mon Mar 19 13:12:30 2012
@@ -0,0 +1,90 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<html xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:ui="http://java.sun.com/jsf/facelets"
+ xmlns:f="http://java.sun.com/jsf/core"
+ xmlns:h="http://java.sun.com/jsf/html"
+ xmlns:t="http://myfaces.apache.org/tomahawk"
+ xmlns:grv="http://myfaces.apache.org/groovy"
+ xmlns:c="http://java.sun.com/jsp/jstl/core">
+<head>
+ <title>Hello World</title>
+</head>
+<body>
+<ui:composition template="/template.xhtml">
+ <ui:define name="body">
+ <h1>
+ <ui:insert name="title">Ext-Scripting Groovy Blog Example</ui:insert>
+ </h1>
+
+ <h:panelGroup styleClass="stdBoxBig" style="color:black;">
+ <h2>In this example you can blog simply by entering text in the fields below and send submit</h2>
+
+ <p>You can change the blogging artifacts on the fly, all the sources can be found under
+ <b>WEB-INF/java/org/apache/myfaces/javaloader/groovy/</b> in your deployment directory</p>
+
+ </h:panelGroup>
+ <h:form id="form">
+ <div class="left" style="margin-top: 3px;">
+ <h:panelGrid id="grid" columns="1" styleClass="stdBox">
+ <h:outputText id="title1" styleClass="title" value="#{blogView.title}"/>
+ <h:outputText id="title11" styleClass="title1" value="#{blogView.title1}"/>
+
+ <hr/>
+
+ <h:panelGrid columns="2" columnClasses="label, input">
+ <h:outputText value="First Name"/>
+ <h:inputText value="#{blogView.firstName}"/>
+ <h:outputText value="Last Name"/>
+ <h:inputText value="#{blogView.lastName}"/>
+ <h:outputText value="Topic of entry"/>
+ <h:inputText value="#{blogView.topic}"/>
+ </h:panelGrid>
+ <h:panelGrid columns="2" columnClasses="label, input">
+ <h:outputText styleClass="label" value="Content"/>
+ <h:inputText value="#{blogView.content}"/>
+ </h:panelGrid>
+ <hr/>
+ <h:commandButton styleClass="btn" action="#{blogView.addEntry}" value="Add Blog Entry">
+ <f:ajax execute="@form" render="content" />
+ </h:commandButton>
+ </h:panelGrid>
+ </div>
+ <h:panelGrid id="content" columns="1" styleClass="right">
+ <ui:repeat value="#{blogService.blogEntries}" var="item">
+ <h:panelGrid columns="1" styleClass="messageBox">
+ <h:panelGroup styleClass="topic">
+ <h:outputLabel styleClass="label" value="Topic"/>
+ <h:outputText value="#{item.topic}"/>
+ </h:panelGroup>
+ <h:panelGroup styleClass="content">
+ <h:outputLabel styleClass="label" value="Content"/>
+ <h:outputFormat escape="false" value="#{item.content}"/>
+ </h:panelGroup>
+ </h:panelGrid>
+ <br/>
+ </ui:repeat>
+ </h:panelGrid>
+ </h:form>
+ </ui:define>
+</ui:composition>
+</body>
+</html>
Modified: myfaces/extensions/scripting/trunk/extscript-examples/blog-example/src/main/webapp/template.xhtml
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-examples/blog-example/src/main/webapp/template.xhtml?rev=1302416&r1=1302415&r2=1302416&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-examples/blog-example/src/main/webapp/template.xhtml (original)
+++ myfaces/extensions/scripting/trunk/extscript-examples/blog-example/src/main/webapp/template.xhtml Mon Mar 19 13:12:30 2012
@@ -34,11 +34,8 @@
<h:body>
<div id="menu">
<h:panelGroup>
- <h:outputLink value="./helloWorld.jsf">Hello world Example</h:outputLink>
<h:outputLink value="./blog.jsf">Groovy Blogging Example</h:outputLink>
<h:outputLink value="./javablog.jsf">Java Blogging Example</h:outputLink>
- <h:outputLink value="./componentTest.jsf">Component Testcase</h:outputLink>
- <h:outputLink value="./compilerWindow.jsf" target="_blank">Compiler Output</h:outputLink>
</h:panelGroup>
</div>