Author: nbelaevski
Date: 2010-07-10 07:50:57 -0400 (Sat, 10 Jul 2010)
New Revision: 17805
Added:
root/examples/misc-demo/trunk/src/main/java/org/richfaces/demo/JQueryBean.java
root/examples/misc-demo/trunk/src/main/webapp/pages/jquery.xhtml
root/ui/misc/trunk/jquery/
root/ui/misc/trunk/jquery/pom.xml
root/ui/misc/trunk/jquery/src/
root/ui/misc/trunk/jquery/src/main/
root/ui/misc/trunk/jquery/src/main/java/
root/ui/misc/trunk/jquery/src/main/java/org/
root/ui/misc/trunk/jquery/src/main/java/org/richfaces/
root/ui/misc/trunk/jquery/src/main/java/org/richfaces/component/
root/ui/misc/trunk/jquery/src/main/java/org/richfaces/component/AbstractJQuery.java
root/ui/misc/trunk/jquery/src/main/java/org/richfaces/component/JQueryAttachTiming.java
root/ui/misc/trunk/jquery/src/main/java/org/richfaces/component/JQueryAttachType.java
root/ui/misc/trunk/jquery/src/main/java/org/richfaces/component/package-info.java
root/ui/misc/trunk/jquery/src/main/java/org/richfaces/renderkit/
root/ui/misc/trunk/jquery/src/main/java/org/richfaces/renderkit/JQueryRendererBase.java
root/ui/misc/trunk/jquery/src/main/resources/
root/ui/misc/trunk/jquery/src/main/resources/META-INF/
root/ui/misc/trunk/jquery/src/main/resources/META-INF/resources/
root/ui/misc/trunk/jquery/src/main/resources/META-INF/resources/org.richfaces/
root/ui/misc/trunk/jquery/src/main/resources/META-INF/resources/org.richfaces/jquery.component.js
root/ui/misc/trunk/jquery/src/main/templates/
root/ui/misc/trunk/jquery/src/main/templates/jquery.template.xml
Modified:
root/examples/misc-demo/trunk/pom.xml
root/ui/misc/trunk/bom/pom.xml
root/ui/misc/trunk/dist/richfaces-ui-misc-ui/pom.xml
root/ui/misc/trunk/pom.xml
Log:
https://jira.jboss.org/browse/RF-8882
Modified: root/examples/misc-demo/trunk/pom.xml
===================================================================
--- root/examples/misc-demo/trunk/pom.xml 2010-07-10 11:46:53 UTC (rev 17804)
+++ root/examples/misc-demo/trunk/pom.xml 2010-07-10 11:50:57 UTC (rev 17805)
@@ -74,6 +74,15 @@
<groupId>org.richfaces.ui.misc</groupId>
<artifactId>richfaces-ui-misc-ui</artifactId>
</dependency>
+ <!-- todo remove this dependency -->
+ <dependency>
+ <groupId>org.richfaces.ui.core</groupId>
+ <artifactId>richfaces-ui-core-ui</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.richfaces.core</groupId>
+ <artifactId>richfaces-core-impl</artifactId>
+ </dependency>
<dependency>
<groupId>${jsf2.api.groupid}</groupId>
@@ -194,5 +203,5 @@
<enabled>true</enabled>
</snapshots>
</repository>
- </repositories>
+ </repositories>
</project>
Added: root/examples/misc-demo/trunk/src/main/java/org/richfaces/demo/JQueryBean.java
===================================================================
--- root/examples/misc-demo/trunk/src/main/java/org/richfaces/demo/JQueryBean.java
(rev 0)
+++
root/examples/misc-demo/trunk/src/main/java/org/richfaces/demo/JQueryBean.java 2010-07-10
11:50:57 UTC (rev 17805)
@@ -0,0 +1,55 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.richfaces.demo;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
+
+import javax.faces.bean.ManagedBean;
+import javax.faces.bean.SessionScoped;
+
+/**
+ * @author nick
+ *
+ */
+@ManagedBean
+@SessionScoped
+public class JQueryBean {
+
+ private List<String> componentsDataList;
+
+ public JQueryBean() {
+ componentsDataList = new ArrayList<String>();
+ addComponent();
+ }
+
+ public List<String> getComponentsDataList() {
+ return componentsDataList;
+ }
+
+ public void addComponent() {
+ componentsDataList.add(UUID.randomUUID().toString());
+ }
+
+}
Added: root/examples/misc-demo/trunk/src/main/webapp/pages/jquery.xhtml
===================================================================
--- root/examples/misc-demo/trunk/src/main/webapp/pages/jquery.xhtml
(rev 0)
+++ root/examples/misc-demo/trunk/src/main/webapp/pages/jquery.xhtml 2010-07-10 11:50:57
UTC (rev 17805)
@@ -0,0 +1,50 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html
xmlns="http://www.w3.org/1999/xhtml"
+
xmlns:f="http://java.sun.com/jsf/core"
+
xmlns:h="http://java.sun.com/jsf/html"
+
xmlns:ui="http://java.sun.com/jsf/facelets"
+
xmlns:misc="http://richfaces.org/misc">
+<f:view>
+ <h:head></h:head>
+ <h:body>
+ <h:panelGroup id="clickTest">
+ Click here
+ </h:panelGroup>
+ <h:outputText value=" | " />
+ <h:panelGroup id="clickTestForReady">
+ Click here
+ </h:panelGroup>
+
+ <misc:jQuery selector="#clickTest" event="click"
query="alert('immediate attachment')" attachTiming="immediate"
/>
+ <misc:jQuery selector="#clickTestForReady" event="click"
query="alert('onready attachment')" attachTiming="onready"
/>
+
+ <misc:jQuery selector="document.body"
query="css({'background-color': '#AAA'})" />
+
+ <br />
+
+ <h:panelGroup id="clickTestOne">
+ Click here - event is attached for one click only
+ </h:panelGroup>
+ <a href="#" onclick="rebindOneClickEvent(); return
false;">Re-enable one-typed click handler</a>
+
+ <misc:jQuery event="click" selector="#clickTestOne"
query="alert('one attachType')" attachType="one" />
+ <misc:jQuery event="click" name="rebindOneClickEvent"
selector="#clickTestOne" query="alert('one attachType rebound
event')" attachType="one" />
+
+ <h:panelGroup id="liveTestGroup">
+ <ui:repeat value="#{jQueryBean.componentsDataList}"
var="data">
+ <h:panelGroup styleClass="liveTestComponent" layout="block"
id="liveTestComponent">
+ Click me #{data}
+ </h:panelGroup>
+ </ui:repeat>
+ </h:panelGroup>
+
+ <h:form>
+ <misc:jQuery selector="#liveTestGroup .liveTestComponent"
attachType="live" event="click"
query="alert(jQuery(this).text())" />
+ <h:commandButton value="Add component for live test"
action="#{jQueryBean.addComponent}">
+ <f:ajax render=":liveTestGroup" />
+ </h:commandButton>
+ </h:form>
+
+ </h:body>
+</f:view>
+</html>
Modified: root/ui/misc/trunk/bom/pom.xml
===================================================================
--- root/ui/misc/trunk/bom/pom.xml 2010-07-10 11:46:53 UTC (rev 17804)
+++ root/ui/misc/trunk/bom/pom.xml 2010-07-10 11:50:57 UTC (rev 17805)
@@ -36,6 +36,7 @@
<properties>
<org.richfaces.core.version>4.0.0-SNAPSHOT</org.richfaces.core.version>
+
<org.richfaces.ui.core.version>4.0.0-SNAPSHOT</org.richfaces.ui.core.version>
</properties>
<dependencyManagement>
@@ -49,6 +50,14 @@
</dependency>
<dependency>
+ <groupId>org.richfaces.ui.core</groupId>
+ <artifactId>richfaces-ui-core-bom</artifactId>
+ <version>${org.richfaces.ui.core.version}</version>
+ <scope>import</scope>
+ <type>pom</type>
+ </dependency>
+
+ <dependency>
<groupId>org.richfaces.ui.misc</groupId>
<artifactId>richfaces-ui-misc-ui</artifactId>
<version>${project.version}</version>
@@ -63,6 +72,11 @@
<artifactId>functions-ui</artifactId>
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.richfaces.ui.misc</groupId>
+ <artifactId>jquery-ui</artifactId>
+ <version>${project.version}</version>
+ </dependency>
</dependencies>
</dependencyManagement>
Modified: root/ui/misc/trunk/dist/richfaces-ui-misc-ui/pom.xml
===================================================================
--- root/ui/misc/trunk/dist/richfaces-ui-misc-ui/pom.xml 2010-07-10 11:46:53 UTC (rev
17804)
+++ root/ui/misc/trunk/dist/richfaces-ui-misc-ui/pom.xml 2010-07-10 11:50:57 UTC (rev
17805)
@@ -50,6 +50,10 @@
<groupId>org.richfaces.ui.misc</groupId>
<artifactId>functions-ui</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.richfaces.ui.misc</groupId>
+ <artifactId>jquery-ui</artifactId>
+ </dependency>
<!-- artifacts for javadoc generation -->
<dependency>
Added: root/ui/misc/trunk/jquery/pom.xml
===================================================================
--- root/ui/misc/trunk/jquery/pom.xml (rev 0)
+++ root/ui/misc/trunk/jquery/pom.xml 2010-07-10 11:50:57 UTC (rev 17805)
@@ -0,0 +1,127 @@
+<!--
+ JBoss, Home of Professional Open Source Copyright 2010, Red Hat,
+ Inc. and individual contributors by the @authors tag. See the
+ copyright.txt in the distribution for a full listing of
+ individual contributors. This is free software; you can
+ redistribute it and/or modify it under the terms of the GNU
+ Lesser General Public License as published by the Free Software
+ Foundation; either version 2.1 of the License, or (at your
+ option) any later version. This software 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 software; if not,
+ write to the Free Software Foundation, Inc., 51 Franklin St,
+ Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF site:
+
http://www.fsf.org.
+-->
+
+<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <parent>
+ <groupId>org.richfaces.ui.misc</groupId>
+ <artifactId>richfaces-ui-misc-parent</artifactId>
+ <version>4.0.0-SNAPSHOT</version>
+ <relativePath>../parent/pom.xml</relativePath>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.richfaces.ui.misc</groupId>
+ <artifactId>jquery-ui</artifactId>
+ <name>Richfaces UI Components: jQuery Component UI</name>
+ <packaging>jar</packaging>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.richfaces.cdk</groupId>
+ <artifactId>maven-cdk-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencies>
+ <!-- runtime -->
+ <dependency>
+ <groupId>org.richfaces.core</groupId>
+ <artifactId>richfaces-core-api</artifactId>
+ </dependency>
+ <dependency>
+ <!-- todo remove this dependency or move to test scope -->
+ <groupId>org.richfaces.core</groupId>
+ <artifactId>richfaces-core-impl</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.richfaces.cdk</groupId>
+ <artifactId>annotations</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ <!-- JSF with dependencies -->
+ <dependency>
+ <groupId>${jsf2.api.groupid}</groupId>
+ <artifactId>${jsf2.api.artifactid}</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet.jsp</groupId>
+ <artifactId>jsp-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.el</groupId>
+ <artifactId>el-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>jstl</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ <!-- tests -->
+ <dependency>
+ <groupId>${jsf2.impl.groupid}</groupId>
+ <artifactId>${jsf2.impl.artifactid}</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <!-- todo api? -->
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.test-jsf</groupId>
+ <artifactId>jsf-test-stage</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.test-jsf</groupId>
+ <artifactId>htmlunit-client</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.test-jsf</groupId>
+ <artifactId>jsf-mock</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <scm>
+
<
connection>scm:svn:http://anonsvn.jboss.org/repos/richfaces/root/ui/mi...
+
<
developerConnection>scm:svn:https://svn.jboss.org/repos/richfaces/root...
+ <
url>http://fisheye.jboss.org/browse/richfaces/</url>
+ </scm>
+</project>
\ No newline at end of file
Added:
root/ui/misc/trunk/jquery/src/main/java/org/richfaces/component/AbstractJQuery.java
===================================================================
--- root/ui/misc/trunk/jquery/src/main/java/org/richfaces/component/AbstractJQuery.java
(rev 0)
+++
root/ui/misc/trunk/jquery/src/main/java/org/richfaces/component/AbstractJQuery.java 2010-07-10
11:50:57 UTC (rev 17805)
@@ -0,0 +1,61 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.richfaces.component;
+
+import javax.faces.component.UIComponentBase;
+
+import org.richfaces.cdk.annotations.Attribute;
+import org.richfaces.cdk.annotations.JsfComponent;
+
+/**
+ * @author nick
+ *
+ */
+@JsfComponent(type = AbstractJQuery.COMPONENT_TYPE, family =
AbstractJQuery.COMPONENT_FAMILY)
+public abstract class AbstractJQuery extends UIComponentBase {
+
+ public static final String COMPONENT_TYPE = "org.richfaces.JQuery";
+
+ public static final String COMPONENT_FAMILY = "org.richfaces.JQuery";
+
+ //TODO nick - CDK should be doing this
+ public AbstractJQuery() {
+ setRendererType("org.richfaces.JQueryRenderer");
+ }
+
+ public abstract String getName();
+
+ public abstract String getSelector();
+
+ public abstract String getEvent();
+
+ public abstract String getQuery();
+
+ @Attribute(defaultValue = "JQueryAttachType.DEFAULT")
+ public abstract JQueryAttachType getAttachType();
+
+ @Attribute(defaultValue = "JQueryAttachTiming.DEFAULT")
+ public abstract JQueryAttachTiming getAttachTiming();
+
+}
+
Added:
root/ui/misc/trunk/jquery/src/main/java/org/richfaces/component/JQueryAttachTiming.java
===================================================================
---
root/ui/misc/trunk/jquery/src/main/java/org/richfaces/component/JQueryAttachTiming.java
(rev 0)
+++
root/ui/misc/trunk/jquery/src/main/java/org/richfaces/component/JQueryAttachTiming.java 2010-07-10
11:50:57 UTC (rev 17805)
@@ -0,0 +1,35 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.richfaces.component;
+
+/**
+ * @author nick
+ *
+ */
+public enum JQueryAttachTiming {
+
+ immediate, onready;
+
+ public static final JQueryAttachTiming DEFAULT = immediate;
+
+}
Added:
root/ui/misc/trunk/jquery/src/main/java/org/richfaces/component/JQueryAttachType.java
===================================================================
--- root/ui/misc/trunk/jquery/src/main/java/org/richfaces/component/JQueryAttachType.java
(rev 0)
+++
root/ui/misc/trunk/jquery/src/main/java/org/richfaces/component/JQueryAttachType.java 2010-07-10
11:50:57 UTC (rev 17805)
@@ -0,0 +1,35 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.richfaces.component;
+
+/**
+ * @author nick
+ *
+ */
+public enum JQueryAttachType {
+
+ bind, live, one;
+
+ public static final JQueryAttachType DEFAULT = bind;
+
+}
Added: root/ui/misc/trunk/jquery/src/main/java/org/richfaces/component/package-info.java
===================================================================
--- root/ui/misc/trunk/jquery/src/main/java/org/richfaces/component/package-info.java
(rev 0)
+++
root/ui/misc/trunk/jquery/src/main/java/org/richfaces/component/package-info.java 2010-07-10
11:50:57 UTC (rev 17805)
@@ -0,0 +1,26 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+/**
+ * Implementation of RichFaces jQuery component
+ */
+@org.richfaces.cdk.annotations.TagLibrary(uri="http://richfaces.org/jquery",
shortName="jquery")
+package org.richfaces.component;
Added:
root/ui/misc/trunk/jquery/src/main/java/org/richfaces/renderkit/JQueryRendererBase.java
===================================================================
---
root/ui/misc/trunk/jquery/src/main/java/org/richfaces/renderkit/JQueryRendererBase.java
(rev 0)
+++
root/ui/misc/trunk/jquery/src/main/java/org/richfaces/renderkit/JQueryRendererBase.java 2010-07-10
11:50:57 UTC (rev 17805)
@@ -0,0 +1,76 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.richfaces.renderkit;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.faces.application.ResourceDependencies;
+import javax.faces.application.ResourceDependency;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.render.Renderer;
+
+import org.ajax4jsf.javascript.ScriptUtils;
+import org.ajax4jsf.renderkit.RendererUtils;
+import org.richfaces.component.AbstractJQuery;
+import org.richfaces.component.JQueryAttachTiming;
+import org.richfaces.component.JQueryAttachType;
+import org.richfaces.component.util.HtmlUtil;
+
+/**
+ * @author nick
+ *
+ */
+@ResourceDependencies({
+ @ResourceDependency(name = "jquery.js"),
+ @ResourceDependency(library = "org.richfaces", name =
"jquery.component.js")
+})
+public abstract class JQueryRendererBase extends Renderer {
+
+ private RendererUtils rendererUtils = RendererUtils.getInstance();
+
+ protected String getEscapedSelector(FacesContext context, UIComponent component) {
+ String selector = (String) component.getAttributes().get("selector");
+
+ if (selector != null) {
+ selector = HtmlUtil.expandIdSelector(selector, component, context);
+ }
+
+ return selector;
+ }
+
+ protected String getOptionsAsJavascriptString(FacesContext context, UIComponent
component) {
+ AbstractJQuery jQuery = (AbstractJQuery) component;
+
+ Map<String,Object> map = new HashMap<String, Object>();
+
+ rendererUtils.addToScriptHash(map, "selector",
getEscapedSelector(context, jQuery));
+ rendererUtils.addToScriptHash(map, "event", jQuery.getEvent());
+ rendererUtils.addToScriptHash(map, "query", jQuery.getQuery());
+ rendererUtils.addToScriptHash(map, "attachType",
jQuery.getAttachType(), JQueryAttachType.DEFAULT.toString());
+ rendererUtils.addToScriptHash(map, "attachTiming",
jQuery.getAttachTiming(), JQueryAttachTiming.DEFAULT.toString());
+
+ return ScriptUtils.toScript(map);
+ }
+}
Added:
root/ui/misc/trunk/jquery/src/main/resources/META-INF/resources/org.richfaces/jquery.component.js
===================================================================
---
root/ui/misc/trunk/jquery/src/main/resources/META-INF/resources/org.richfaces/jquery.component.js
(rev 0)
+++
root/ui/misc/trunk/jquery/src/main/resources/META-INF/resources/org.richfaces/jquery.component.js 2010-07-10
11:50:57 UTC (rev 17805)
@@ -0,0 +1,68 @@
+if (!window.RichFaces) {
+ window.RichFaces = {};
+}
+
+(function(jquery, richfaces) {
+
+ var evaluateSelector = function(selector) {
+ var result = selector;
+ try {
+ result = eval(selector);
+ } catch (e) {
+ //do nothing
+ }
+ return result || "";
+ };
+
+ var createHandler = function(handler) {
+ if (typeof handler == 'function') {
+ return handler;
+ } else {
+ return new Function("event", handler);
+ }
+ };
+
+ var bindFunction = function(options) {
+
+ var selector = evaluateSelector(options.selector);
+ var query = options.query;
+
+ if (options.event) {
+ var handler = createHandler(query);
+
+ if (options.attachType == 'live') {
+ jQuery(selector).live(options.event, handler);
+ } else if (options.attachType == 'one') {
+ jQuery(selector).one(options.event, handler);
+ } else {
+ jQuery(selector).bind(options.event, handler);
+ }
+ } else {
+ var f = new Function("__locatedObject", "__locatedObject." +
query);
+ f.call(this, jQuery(selector));
+ //TODO return value?
+ }
+ };
+
+ var bind = function(options) {
+ if (options.attachTimimg == 'immediate') {
+ bindFunction(options);
+ } else {
+ jQuery(document).ready(function() {
+ bindFunction(options);
+ });
+ }
+ };
+
+ richfaces.jQuery = {
+
+ bind: bind,
+
+ createBinder: function(options) {
+ return function() {
+ bind(options);
+ };
+ }
+ };
+
+}(jQuery, RichFaces));
Added: root/ui/misc/trunk/jquery/src/main/templates/jquery.template.xml
===================================================================
--- root/ui/misc/trunk/jquery/src/main/templates/jquery.template.xml
(rev 0)
+++ root/ui/misc/trunk/jquery/src/main/templates/jquery.template.xml 2010-07-10 11:50:57
UTC (rev 17805)
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<cdk:root
xmlns="http://richfaces.org/cdk/xhtml-el"
xmlns:cdk="http://richfaces.org/cdk/core"
+
xmlns:c="http://richfaces.org/cdk/jstl/core"
xmlns:cc="http://richfaces.org/cdk/jsf/composite"
+
xmlns:javaee="http://java.sun.com/xml/ns/javaee">
+
+ <cc:interface>
+ <cdk:class>org.richfaces.renderkit.html.JQueryRenderer</cdk:class>
+
<cdk:superclass>org.richfaces.renderkit.JQueryRendererBase</cdk:superclass>
+ <cdk:component-family>org.richfaces.JQuery</cdk:component-family>
+ <cdk:renderer-type>org.richfaces.JQueryRenderer</cdk:renderer-type>
+ <cdk:renders-children>true</cdk:renders-children>
+ </cc:interface>
+
+ <cc:implementation>
+ <span id="#{clientId}" style="display: none;">
+ <script type="text/javascript">
+ <cdk:object name="functionName"
value="#{component.attributes['name']}" />
+ <cdk:object name="options"
value="#{getOptionsAsJavascriptString(facesContext, component)}" />
+
+ <c:choose>
+ <c:when test="#{not empty functionName}">
+ #{functionName} = RichFaces.jQuery.createBinder(#{options});
+ </c:when>
+ <c:otherwise>
+ RichFaces.jQuery.bind(#{options});
+ </c:otherwise>
+ </c:choose>
+ </script>
+ </span>
+ </cc:implementation>
+
+</cdk:root>
Modified: root/ui/misc/trunk/pom.xml
===================================================================
--- root/ui/misc/trunk/pom.xml 2010-07-10 11:46:53 UTC (rev 17804)
+++ root/ui/misc/trunk/pom.xml 2010-07-10 11:50:57 UTC (rev 17805)
@@ -39,6 +39,7 @@
<module>parent</module>
<module>functions</module>
<module>componentcontrol</module>
+ <module>jquery</module>
<!-- assembler -->
<module>dist</module>