You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lo...@apache.org on 2013/01/29 11:32:39 UTC
svn commit: r1439818 - in
/myfaces/tobago/branches/tobago-1.5.x/tobago-example/tobago-example-test/src/main:
java/org/apache/myfaces/tobago/example/test/ webapp/WEB-INF/
webapp/test/script/
Author: lofwyr
Date: Tue Jan 29 10:32:39 2013
New Revision: 1439818
URL: http://svn.apache.org/viewvc?rev=1439818&view=rev
Log:
test for onload/onunload/onexit
Added:
myfaces/tobago/branches/tobago-1.5.x/tobago-example/tobago-example-test/src/main/java/org/apache/myfaces/tobago/example/test/ScriptEvent.java
myfaces/tobago/branches/tobago-1.5.x/tobago-example/tobago-example-test/src/main/java/org/apache/myfaces/tobago/example/test/ScriptEventItem.java
myfaces/tobago/branches/tobago-1.5.x/tobago-example/tobago-example-test/src/main/java/org/apache/myfaces/tobago/example/test/ScriptEventServlet.java
myfaces/tobago/branches/tobago-1.5.x/tobago-example/tobago-example-test/src/main/webapp/test/script/script-event.js
myfaces/tobago/branches/tobago-1.5.x/tobago-example/tobago-example-test/src/main/webapp/test/script/script-event.xhtml
- copied, changed from r1412140, myfaces/tobago/branches/tobago-1.5.x/tobago-example/tobago-example-test/src/main/webapp/test/resource/tobago-694.xhtml
Modified:
myfaces/tobago/branches/tobago-1.5.x/tobago-example/tobago-example-test/src/main/webapp/WEB-INF/faces-config.xml
myfaces/tobago/branches/tobago-1.5.x/tobago-example/tobago-example-test/src/main/webapp/WEB-INF/web.xml
Added: myfaces/tobago/branches/tobago-1.5.x/tobago-example/tobago-example-test/src/main/java/org/apache/myfaces/tobago/example/test/ScriptEvent.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-1.5.x/tobago-example/tobago-example-test/src/main/java/org/apache/myfaces/tobago/example/test/ScriptEvent.java?rev=1439818&view=auto
==============================================================================
--- myfaces/tobago/branches/tobago-1.5.x/tobago-example/tobago-example-test/src/main/java/org/apache/myfaces/tobago/example/test/ScriptEvent.java (added)
+++ myfaces/tobago/branches/tobago-1.5.x/tobago-example/tobago-example-test/src/main/java/org/apache/myfaces/tobago/example/test/ScriptEvent.java Tue Jan 29 10:32:39 2013
@@ -0,0 +1,49 @@
+/*
+ * 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 org.apache.myfaces.tobago.example.test;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class ScriptEvent {
+
+ private List<ScriptEventItem> items = new ArrayList<ScriptEventItem>();
+
+ public void onLoad() {
+ items.add(new ScriptEventItem("onload"));
+ }
+
+ public void onUnload() {
+ items.add(new ScriptEventItem("onunload"));
+ }
+
+ public void onExit() {
+ items.add(new ScriptEventItem("onexit"));
+ }
+
+ public String action() {
+ items.add(new ScriptEventItem("action"));
+ return null;
+ }
+
+ public List<ScriptEventItem> getItems() {
+ return items;
+ }
+}
Added: myfaces/tobago/branches/tobago-1.5.x/tobago-example/tobago-example-test/src/main/java/org/apache/myfaces/tobago/example/test/ScriptEventItem.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-1.5.x/tobago-example/tobago-example-test/src/main/java/org/apache/myfaces/tobago/example/test/ScriptEventItem.java?rev=1439818&view=auto
==============================================================================
--- myfaces/tobago/branches/tobago-1.5.x/tobago-example/tobago-example-test/src/main/java/org/apache/myfaces/tobago/example/test/ScriptEventItem.java (added)
+++ myfaces/tobago/branches/tobago-1.5.x/tobago-example/tobago-example-test/src/main/java/org/apache/myfaces/tobago/example/test/ScriptEventItem.java Tue Jan 29 10:32:39 2013
@@ -0,0 +1,47 @@
+/*
+ * 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 org.apache.myfaces.tobago.example.test;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Date;
+
+public class ScriptEventItem {
+
+ private static final Logger LOG = LoggerFactory.getLogger(ScriptEventItem.class);
+
+ private String name;
+ private Date time;
+
+ public ScriptEventItem(String name) {
+ this.name = name;
+ this.time = new Date();
+ LOG.info(name);
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public Date getTime() {
+ return time;
+ }
+}
Added: myfaces/tobago/branches/tobago-1.5.x/tobago-example/tobago-example-test/src/main/java/org/apache/myfaces/tobago/example/test/ScriptEventServlet.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-1.5.x/tobago-example/tobago-example-test/src/main/java/org/apache/myfaces/tobago/example/test/ScriptEventServlet.java?rev=1439818&view=auto
==============================================================================
--- myfaces/tobago/branches/tobago-1.5.x/tobago-example/tobago-example-test/src/main/java/org/apache/myfaces/tobago/example/test/ScriptEventServlet.java (added)
+++ myfaces/tobago/branches/tobago-1.5.x/tobago-example/tobago-example-test/src/main/java/org/apache/myfaces/tobago/example/test/ScriptEventServlet.java Tue Jan 29 10:32:39 2013
@@ -0,0 +1,57 @@
+/*
+ * 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 org.apache.myfaces.tobago.example.test;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+import java.io.IOException;
+
+public class ScriptEventServlet extends HttpServlet {
+
+ private static final Logger LOG = LoggerFactory.getLogger(ScriptEventServlet.class);
+
+ @Override
+ protected void doGet(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
+ final HttpSession session = request.getSession(false);
+ if (session != null) {
+ final ScriptEvent scriptEvent = (ScriptEvent) session.getAttribute("scriptEvent");
+ if (scriptEvent != null) {
+ String event = request.getParameter("event");
+ if (event.equals("onload")) {
+ scriptEvent.onLoad();
+ } else if (event.equals("onunload")) {
+ scriptEvent.onUnload();
+ } else if (event.equals("onexit")) {
+ scriptEvent.onExit();
+ } else {
+ LOG.warn("Unknown event");
+ }
+ }
+ }
+ response.getOutputStream().write("done".getBytes());
+ }
+}
Modified: myfaces/tobago/branches/tobago-1.5.x/tobago-example/tobago-example-test/src/main/webapp/WEB-INF/faces-config.xml
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-1.5.x/tobago-example/tobago-example-test/src/main/webapp/WEB-INF/faces-config.xml?rev=1439818&r1=1439817&r2=1439818&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-1.5.x/tobago-example/tobago-example-test/src/main/webapp/WEB-INF/faces-config.xml (original)
+++ myfaces/tobago/branches/tobago-1.5.x/tobago-example/tobago-example-test/src/main/webapp/WEB-INF/faces-config.xml Tue Jan 29 10:32:39 2013
@@ -179,6 +179,12 @@
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
+ <managed-bean>
+ <managed-bean-name>scriptEvent</managed-bean-name>
+ <managed-bean-class>org.apache.myfaces.tobago.example.test.ScriptEvent</managed-bean-class>
+ <managed-bean-scope>session</managed-bean-scope>
+ </managed-bean>
+
<navigation-rule>
<navigation-case>
<from-outcome>navigation</from-outcome>
Modified: myfaces/tobago/branches/tobago-1.5.x/tobago-example/tobago-example-test/src/main/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-1.5.x/tobago-example/tobago-example-test/src/main/webapp/WEB-INF/web.xml?rev=1439818&r1=1439817&r2=1439818&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-1.5.x/tobago-example/tobago-example-test/src/main/webapp/WEB-INF/web.xml (original)
+++ myfaces/tobago/branches/tobago-1.5.x/tobago-example/tobago-example-test/src/main/webapp/WEB-INF/web.xml Tue Jan 29 10:32:39 2013
@@ -70,6 +70,19 @@
<servlet-name>KillSessionServlet</servlet-name>
<servlet-class>org.apache.myfaces.tobago.example.test.KillSession</servlet-class>
</servlet>
+ <servlet-mapping>
+ <servlet-name>KillSessionServlet</servlet-name>
+ <url-pattern>/KillSession</url-pattern>
+ </servlet-mapping>
+
+ <servlet>
+ <servlet-name>ScriptEventServlet</servlet-name>
+ <servlet-class>org.apache.myfaces.tobago.example.test.ScriptEventServlet</servlet-class>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>ScriptEventServlet</servlet-name>
+ <url-pattern>/ScriptEventServlet</url-pattern>
+ </servlet-mapping>
<servlet-mapping>
<servlet-name>FacesServlet</servlet-name>
@@ -81,11 +94,6 @@
<url-pattern>/org/apache/myfaces/tobago/renderkit/html/*</url-pattern>
</servlet-mapping>
- <servlet-mapping>
- <servlet-name>KillSessionServlet</servlet-name>
- <url-pattern>/KillSession</url-pattern>
- </servlet-mapping>
-
<filter>
<filter-name>MyFacesExtensionsFilter</filter-name>
<filter-class>org.apache.myfaces.webapp.filter.ExtensionsFilter</filter-class>
Added: myfaces/tobago/branches/tobago-1.5.x/tobago-example/tobago-example-test/src/main/webapp/test/script/script-event.js
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-1.5.x/tobago-example/tobago-example-test/src/main/webapp/test/script/script-event.js?rev=1439818&view=auto
==============================================================================
--- myfaces/tobago/branches/tobago-1.5.x/tobago-example/tobago-example-test/src/main/webapp/test/script/script-event.js (added)
+++ myfaces/tobago/branches/tobago-1.5.x/tobago-example/tobago-example-test/src/main/webapp/test/script/script-event.js Tue Jan 29 10:32:39 2013
@@ -0,0 +1,37 @@
+/*
+ * 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.
+ */
+
+ScriptEvent = {};
+
+ScriptEvent.onload = function() {
+ jQuery.ajax({url:"/ScriptEventServlet?event=onload",async:false});
+};
+
+ScriptEvent.onunload = function() {
+ jQuery.ajax({url:"/ScriptEventServlet?event=onunload",async:false});
+};
+
+ScriptEvent.onexit = function() {
+ jQuery.ajax({url:"/ScriptEventServlet?event=onexit",async:false});
+};
+
+function showTime() {
+ jQuery(Tobago.Utils.escapeClientId("page:list")).find(".tobago-box-header").html(formatDate(new Date(), "hh:mm:ss"));
+ setTimeout(showTime, 500);
+}
+
+setTimeout(showTime, 0);
Copied: myfaces/tobago/branches/tobago-1.5.x/tobago-example/tobago-example-test/src/main/webapp/test/script/script-event.xhtml (from r1412140, myfaces/tobago/branches/tobago-1.5.x/tobago-example/tobago-example-test/src/main/webapp/test/resource/tobago-694.xhtml)
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-1.5.x/tobago-example/tobago-example-test/src/main/webapp/test/script/script-event.xhtml?p2=myfaces/tobago/branches/tobago-1.5.x/tobago-example/tobago-example-test/src/main/webapp/test/script/script-event.xhtml&p1=myfaces/tobago/branches/tobago-1.5.x/tobago-example/tobago-example-test/src/main/webapp/test/resource/tobago-694.xhtml&r1=1412140&r2=1439818&rev=1439818&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-1.5.x/tobago-example/tobago-example-test/src/main/webapp/test/resource/tobago-694.xhtml (original)
+++ myfaces/tobago/branches/tobago-1.5.x/tobago-example/tobago-example-test/src/main/webapp/test/script/script-event.xhtml Tue Jan 29 10:32:39 2013
@@ -19,26 +19,56 @@
<f:view
xmlns:tc="http://myfaces.apache.org/tobago/component"
xmlns:tx="http://myfaces.apache.org/tobago/extension"
- xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core">
- <tc:page>
+ <tc:page id="page">
<f:facet name="layout">
- <tc:gridLayout rows="auto;auto;auto;auto;*" columns="auto"/>
+ <tc:gridLayout columns="*;*" rows="auto;*"/>
</f:facet>
<tc:gridLayoutConstraint width="600px" height="300px"/>
- <tc:messages/>
-
- <tc:image value="image/wait/cat.jpg">
- <tc:gridLayoutConstraint width="100px" height="106px"/>
- </tc:image>
-
- <tx:in label="Counter:" value="#{reload.counter}" readonly="true"/>
-
- <tc:button label="submit" action="#{reload.isReload}"/>
-
- <tc:cell/>
+ <tc:messages>
+ <tc:gridLayoutConstraint columnSpan="2" />
+ </tc:messages>
+
+ <tc:box id="panel">
+ <f:facet name="layout">
+ <tc:gridLayout rows="*;auto;auto;auto"/>
+ </f:facet>
+
+ <tc:script
+ file="test/script/script-event.js"
+ onload="ScriptEvent.onload();"
+ onunload="ScriptEvent.onunload();"
+ onexit="ScriptEvent.onexit();">
+ </tc:script>
+
+ <tc:out value="TODO: write an automated tests."/>
+
+ <tc:button label="No Action"/>
+ <tc:button label="Action" action="#{scriptEvent.action}"/>
+ <tc:button label="External link" link="http://www.apache.org" target="_blank"/>
+
+ </tc:box>
+
+ <tc:box id="list" label="time">
+ <f:facet name="layout">
+ <tc:gridLayout rows="auto;*"/>
+ </f:facet>
+
+ <tc:button label="Reload List" renderedPartially="list"/>
+
+ <tc:sheet value="#{scriptEvent.items}" var="item">
+ <tc:column label="Event">
+ <tc:out value="#{item.name}"/>
+ </tc:column>
+ <tc:column label="Time">
+ <tc:out value="#{item.time}">
+ <f:convertDateTime timeStyle="long" type="time"/>
+ </tc:out>
+ </tc:column>
+ </tc:sheet>
+ </tc:box>
</tc:page>
</f:view>