JBoss Rich Faces SVN: r19585 - trunk/core/api/src/main/java/org/ajax4jsf/javascript.
by richfaces-svn-commits@lists.jboss.org
Author: amarkhel
Date: 2010-10-15 14:47:06 -0400 (Fri, 15 Oct 2010)
New Revision: 19585
Modified:
trunk/core/api/src/main/java/org/ajax4jsf/javascript/JSLiteral.java
Log:
RF-9512
Modified: trunk/core/api/src/main/java/org/ajax4jsf/javascript/JSLiteral.java
===================================================================
--- trunk/core/api/src/main/java/org/ajax4jsf/javascript/JSLiteral.java 2010-10-15 17:07:02 UTC (rev 19584)
+++ trunk/core/api/src/main/java/org/ajax4jsf/javascript/JSLiteral.java 2010-10-15 18:47:06 UTC (rev 19585)
@@ -23,12 +23,14 @@
package org.ajax4jsf.javascript;
+import java.io.Serializable;
+
/**
* Class provides creation of simple literal javascript to be set in ajax response data
* @author Andrey Markavtsov
*
*/
-public class JSLiteral extends ScriptStringBase {
+public class JSLiteral extends ScriptStringBase implements Serializable{
public static final JSLiteral EMPTY_HASH = new ImmutableJSLiteral("{}");
public static final JSLiteral EMPTY_LIST = new ImmutableJSLiteral("[]");
13 years, 8 months
JBoss Rich Faces SVN: r19584 - in trunk/ui/input/ui/src/main: java/org/richfaces/renderkit and 2 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: abelevich
Date: 2010-10-15 13:07:02 -0400 (Fri, 15 Oct 2010)
New Revision: 19584
Modified:
trunk/ui/input/ui/src/main/java/org/richfaces/component/AbstractSelect.java
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/ClientSelectItem.java
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/InputRendererBase.java
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/PopupConstants.java
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/SelectHelper.java
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/SelectRendererBase.java
trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/select.ecss
trunk/ui/input/ui/src/main/templates/select.template.xml
Log:
fix css classes names, add/update license headers
Modified: trunk/ui/input/ui/src/main/java/org/richfaces/component/AbstractSelect.java
===================================================================
--- trunk/ui/input/ui/src/main/java/org/richfaces/component/AbstractSelect.java 2010-10-15 16:50:55 UTC (rev 19583)
+++ trunk/ui/input/ui/src/main/java/org/richfaces/component/AbstractSelect.java 2010-10-15 17:07:02 UTC (rev 19584)
@@ -1,3 +1,25 @@
+/*
+ * 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.UISelectOne;
@@ -9,6 +31,10 @@
import org.richfaces.cdk.annotations.Tag;
+/**
+ * @author abelevich
+ *
+ */
@JsfComponent(
type = AbstractSelect.COMPONENT_TYPE,
family = AbstractSelect.COMPONENT_FAMILY,
@@ -76,13 +102,14 @@
@Attribute(events=@EventName("change"))
public abstract String getOnchange();
- @Attribute(defaultValue = "rf-au-opt")
+ @Attribute(defaultValue = "rf-sel-opt")
public abstract String getItemCss();
- @Attribute(defaultValue = "rf-au-sel")
+ //TODO: rename css class "rf-sel-opt-sel"
+ @Attribute(defaultValue = "rf-sel-sel")
public abstract String getSelectItemCss();
- @Attribute(defaultValue = "rf-au-lst-cord")
+ @Attribute(defaultValue = "rf-sel-lst-cord")
public abstract String getListCss();
Modified: trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/ClientSelectItem.java
===================================================================
--- trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/ClientSelectItem.java 2010-10-15 16:50:55 UTC (rev 19583)
+++ trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/ClientSelectItem.java 2010-10-15 17:07:02 UTC (rev 19584)
@@ -1,3 +1,25 @@
+/*
+ * 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 org.ajax4jsf.javascript.ScriptString;
Modified: trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/InputRendererBase.java
===================================================================
--- trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/InputRendererBase.java 2010-10-15 16:50:55 UTC (rev 19583)
+++ trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/InputRendererBase.java 2010-10-15 17:07:02 UTC (rev 19584)
@@ -1,22 +1,23 @@
-/**
- * License Agreement.
+/*
+ * 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.
*
- * JBoss RichFaces - Ajax4jsf Component Library
+ * 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.
*
- * 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,
+ * 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
+ * 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
+ * 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;
Modified: trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/PopupConstants.java
===================================================================
--- trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/PopupConstants.java 2010-10-15 16:50:55 UTC (rev 19583)
+++ trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/PopupConstants.java 2010-10-15 17:07:02 UTC (rev 19584)
@@ -1,3 +1,25 @@
+/*
+ * 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;
/**
Modified: trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/SelectHelper.java
===================================================================
--- trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/SelectHelper.java 2010-10-15 16:50:55 UTC (rev 19583)
+++ trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/SelectHelper.java 2010-10-15 17:07:02 UTC (rev 19584)
@@ -1,3 +1,25 @@
+/*
+ * 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.io.IOException;
@@ -21,6 +43,12 @@
*/
public final class SelectHelper {
+ public static final String OPTIONS_SHOWCONTROL = "showControl";
+
+ public static final String OPTIONS_SELECT_ITEM_VALUE_INPUT = "selValueInput";
+
+ public static final String OPTIONS_LIST_ITEMS = "items";
+
public static final Map<String, ComponentAttribute> SELECT_LIST_HANDLER_ATTRIBUTES = Collections
.unmodifiableMap(ComponentAttribute.createMap(
new ComponentAttribute(HtmlConstants.ONCLICK_ATTRIBUTE)
Modified: trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/SelectRendererBase.java
===================================================================
--- trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/SelectRendererBase.java 2010-10-15 16:50:55 UTC (rev 19583)
+++ trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/SelectRendererBase.java 2010-10-15 17:07:02 UTC (rev 19584)
@@ -1,3 +1,25 @@
+/*
+ * 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.io.IOException;
@@ -25,15 +47,7 @@
@ResourceDependency(library = "org.richfaces", name = "select.js"),
@ResourceDependency(library = "org.richfaces", name = "select.ecss") })
public class SelectRendererBase extends InputRendererBase {
-
- //TODO: move to SelectHelper <!--
- public static final String OPTION_SHOWCONTROL = "showControl";
-
- public static final String OPTIONS_SELECT_ITEM_VALUE_INPUT = "selValueInput";
- public static final String OPTION_LIST_ITEMS = "items";
- // -->
-
public void renderListHandlers(FacesContext facesContext, UIComponent component) throws IOException {
RenderKitUtils.renderPassThroughAttributesOptimized(facesContext, component, SelectHelper.SELECT_LIST_HANDLER_ATTRIBUTES);
}
@@ -62,8 +76,8 @@
String clientId = abstractSelect.getClientId(facesContext);
Map<String, Object> options = new HashMap<String, Object>();
- options.put(OPTION_SHOWCONTROL, abstractSelect.isShowButton());
- options.put(OPTION_LIST_ITEMS, selectItems);
+ options.put(SelectHelper.OPTIONS_SHOWCONTROL, abstractSelect.isShowButton());
+ options.put(SelectHelper.OPTIONS_LIST_ITEMS, selectItems);
options.put(PopupConstants.OPTIONS_ITEM_CLASS, abstractSelect.getItemCss());
options.put(PopupConstants.OPTIONS_SELECT_ITEM_CLASS, abstractSelect.getSelectItemCss());
options.put(PopupConstants.OPTIONS_LIST_CLASS, abstractSelect.getListCss());
@@ -86,8 +100,4 @@
protected String getScriptName() {
return "new RichFaces.ui.Select";
}
-
- public String getListStyles(FacesContext facesContext, UIComponent component) {
- return "";
- }
}
Modified: trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/select.ecss
===================================================================
--- trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/select.ecss 2010-10-15 16:50:55 UTC (rev 19583)
+++ trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/select.ecss 2010-10-15 17:07:02 UTC (rev 19584)
@@ -1,17 +1,17 @@
-.rf-au-inp.rf-au-fnt, .rf-au-opt.rf-au-fnt{
+.rf-sel-inp.rf-s-fnt, .rf-sel-opt.rf-sel-fnt{
color: '#{richSkin.generalTextColor}';
font-size: '#{richSkin.generalSizeFont}';
font-family: '#{richSkin.generalFamilyFont}';
}
-input.rf-au-inp {
+input.rf-sel-inp {
border-width: 0px;
background: none;
width: 100%;
}
-.rf-au-fld{
+.rf-sel-fld{
width: 200px;
position: inline-block;
border-width: 1px;
@@ -24,7 +24,7 @@
background-color: '#{richSkin.controlBackgroundColor}';
}
-.rf-au-btn{
+.rf-sel-btn{
background-image: "url(#{resource['org.richfaces.renderkit.html.images.AutocompleteButtonGradient']})";
background-repeat: repeat-x;
background-position: top left;
@@ -41,7 +41,7 @@
padding-top: 1px
}
-.rf-au-btn-arrow{
+.rf-sel-btn-arrow{
background-position: center;
background-repeat: no-repeat;
background-image: "url(#{resource['org.richfaces:combo_down_button.gif']})";
@@ -50,13 +50,13 @@
height: 15px;
}
-.rf-au-lst-cord{
+.rf-sel-lst-cord{
position: absolute;
/* TODO nick - review: font-size: 0px; */
display: none;
}
-.rf-au-lst-dcrtn{
+.rf-sel-lst-dcrtn{
border-width: 1px;
border-style: solid;
border-color: '#{richSkin.panelBorderColor}';
@@ -64,7 +64,7 @@
background-color: '#{richSkin.tableBackgroundColor}';
}
-.rf-au-lst-scrl{
+.rf-sel-lst-scrl{
overflow: auto;
overflow-x: hidden;
width: 200px;
@@ -72,14 +72,14 @@
min-height: 20px;
}
-.rf-au-opt{
+.rf-sel-opt{
padding: 2px;
white-space: nowrap;
cursor: default;
list-style-type: none;
}
-.rf-au-sel{
+.rf-sel-sel{
padding: 1px;
width: 100%;
background-color: '#{richSkin.headerBackgroundColor}';
@@ -88,7 +88,7 @@
border-color: '#{richSkin.generalTextColor}';
}
-.rf-au-shdw{
+.rf-sel-shdw{
border: 0px solid red;
display: inline-block;
position: absolute;
@@ -98,7 +98,7 @@
left: -7px;
}
-.rf-au-shdw-t{
+.rf-sel-shdw-t{
background-image: "url(#{resource['org.richfaces:combo_list_shadow.png']})";
background-position: top left;
position: absolute;
@@ -108,7 +108,7 @@
left: 0px
}
-.rf-au-shdw-l{
+.rf-sel-shdw-l{
background-image: "url(#{resource['org.richfaces:combo_list_shadow.png']})";
background-position: bottom left;
position: absolute;
@@ -118,7 +118,7 @@
right: 6px;
}
-.rf-au-shdw-r{
+.rf-sel-u-shdw-r{
background-image: "url(#{resource['org.richfaces:combo_list_shadow.png']})";
background-position: bottom right;
position: absolute;
@@ -128,7 +128,7 @@
right: 0px;
}
-.rf-au-shdw-b{
+.rf-sel-shdw-b{
background-image: "url(#{resource['org.richfaces:combo_list_shadow.png']})";
background-position: right top;
position: absolute;
@@ -138,7 +138,7 @@
right: 0px;
}
-.rf-au-lst-ul{
+.rf-sel-lst-ul{
margin: 0px;
padding: 0px;
}
\ No newline at end of file
Modified: trunk/ui/input/ui/src/main/templates/select.template.xml
===================================================================
--- trunk/ui/input/ui/src/main/templates/select.template.xml 2010-10-15 16:50:55 UTC (rev 19583)
+++ trunk/ui/input/ui/src/main/templates/select.template.xml 2010-10-15 17:07:02 UTC (rev 19584)
@@ -19,7 +19,7 @@
<cdk:object type="java.lang.Object" name="disabled" value="#{component.attributes['disabled']}" />
- <div id="#{clientId}" class="rf-au-fld">
+ <div id="#{clientId}" class="rf-sel-fld">
<div style="position : relative; overflow : hidden; text-align : left; padding-right : 21px;">
<input id="#{clientId}selValue" name="#{clientId}" type="hidden" value="#{getValue(facesContext, component)}"/>
<input cdk:passThroughWithExclusions="class autocomplete id value disabled name type readonly"
@@ -27,34 +27,34 @@
value="#{getSelectInputLabel(facesContext, component)}"
disabled="#{disabled}"
type="text"
- class="rf-au-fnt rf-au-inp"
+ class="rf-sel-fnt rf-sel-inp"
autocomplete="off"
readonly="readonly"/>
<c:if test="#{component.attributes['showButton']}">
<c:if test="#{component.attributes['disabled']}">
- <div id="#{clientId}Button" class="rf-au-btn">
- <div class="rf-au-btn-arrow"></div>
+ <div id="#{clientId}Button" class="rf-sel-btn">
+ <div class="rf-sel-btn-arrow"></div>
</div>
</c:if>
<c:if test="#{!component.attributes['disabled']}">
- <div id="#{clientId}Button" class="rf-au-btn">
- <div class="rf-au-btn-arrow"></div>
+ <div id="#{clientId}Button" class="rf-sel-btn">
+ <div class="rf-sel-btn-arrow"></div>
</div>
</c:if>
</c:if>
</div>
- <div id="#{clientId}List" class="rf-au-lst-cord">
+ <div id="#{clientId}List" class="rf-sel-lst-cord">
<cdk:call expression="renderListHandlers(facesContext, component);"/>
- <div class="rf-au-shdw">
- <div class="rf-au-shdw-t"></div>
- <div class="rf-au-shdw-l"></div>
- <div class="rf-au-shdw-r"></div>
- <div class="rf-au-shdw-b"></div>
+ <div class="rf-sel-shdw">
+ <div class="rf-sel-shdw-t"></div>
+ <div class="rf-sel-shdw-l"></div>
+ <div class="rf-sel-shdw-r"></div>
+ <div class="rf-sel-shdw-b"></div>
- <div class="rf-au-lst-dcrtn">
- <div class="rf-au-lst-scrl">
+ <div class="rf-sel-lst-dcrtn">
+ <div class="rf-sel-lst-scrl">
<cdk:call expression="encodeItems(facesContext, component, clientSelectItems);"/>
</div>
</div>
13 years, 8 months
JBoss Rich Faces SVN: r19583 - trunk/examples/input-demo/src/main/webapp/examples.
by richfaces-svn-commits@lists.jboss.org
Author: abelevich
Date: 2010-10-15 12:50:55 -0400 (Fri, 15 Oct 2010)
New Revision: 19583
Added:
trunk/examples/input-demo/src/main/webapp/examples/select.xhtml
Modified:
trunk/examples/input-demo/src/main/webapp/examples/inplaceSelect.xhtml
Log:
fix inplaceSelect; add select sample
Modified: trunk/examples/input-demo/src/main/webapp/examples/inplaceSelect.xhtml
===================================================================
--- trunk/examples/input-demo/src/main/webapp/examples/inplaceSelect.xhtml 2010-10-15 16:45:47 UTC (rev 19582)
+++ trunk/examples/input-demo/src/main/webapp/examples/inplaceSelect.xhtml 2010-10-15 16:50:55 UTC (rev 19583)
@@ -7,7 +7,7 @@
<f:view contentType="text/html" />
<h:head>
- <title>InplaceInput</title>
+ <title>InplaceSelect</title>
</h:head>
@@ -15,7 +15,7 @@
<h:form id="form">
<div id="scroll" style="width: 400px; height:400px; overflow:auto;" >
<fieldset>
- <legend>Test App</legend>
+ <legend>InplaceSelect Test App</legend>
Fresh off his victory in the Florida primary, Sen. John McCain is poised to take another big prize. Former
<in:inplaceSelect defaultLabel="Edit Text" value="#{inputBean.value}">
<f:selectItem itemLabel="1#OptionLabel" itemValue="1#OptionValue"/>
Added: trunk/examples/input-demo/src/main/webapp/examples/select.xhtml
===================================================================
--- trunk/examples/input-demo/src/main/webapp/examples/select.xhtml (rev 0)
+++ trunk/examples/input-demo/src/main/webapp/examples/select.xhtml 2010-10-15 16:50:55 UTC (rev 19583)
@@ -0,0 +1,33 @@
+<!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:h="http://java.sun.com/jsf/html"
+ xmlns:f="http://java.sun.com/jsf/core"
+ xmlns:ui="http://java.sun.com/jsf/facelets"
+ xmlns:in="http://richfaces.org/input">
+<f:view contentType="text/html" />
+
+<h:head>
+ <title>Select</title>
+</h:head>
+
+
+<h:body>
+ <h:form id="form">
+ <div id="scroll" style="width: 400px; height:400px; overflow:auto;" >
+ <fieldset>
+ <legend>Select Test App</legend>
+ <in:select defaultLabel="Select Value ..." value="#{inputBean.value}">
+ <f:selectItem itemLabel="Label#1" itemValue="Value#1"/>
+ <f:selectItem itemLabel="Label#2" itemValue="Value#2"/>
+ <f:selectItem itemLabel="Label#3" itemValue="Value#3"/>
+ <f:selectItem itemLabel="Label#4" itemValue="Value#4"/>
+ </in:select>
+ </fieldset>
+ <h:commandButton value="submit"></h:commandButton>
+ </div>
+ <h:panelGroup id="out">
+ <h:outputText value="Selected Value: #{inputBean.value}"/>
+ </h:panelGroup>
+ </h:form>
+</h:body>
+</html>
13 years, 8 months
JBoss Rich Faces SVN: r19582 - in trunk/ui/input/ui/src/main: java/org/richfaces/renderkit and 2 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: abelevich
Date: 2010-10-15 12:45:47 -0400 (Fri, 15 Oct 2010)
New Revision: 19582
Added:
trunk/ui/input/ui/src/main/java/org/richfaces/component/AbstractSelect.java
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/ClientSelectItem.java
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/InplaceInputRendererBase.java
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/InplaceSelectRendererBase.java
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/PopupConstants.java
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/SelectHelper.java
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/SelectRendererBase.java
trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/select.ecss
trunk/ui/input/ui/src/main/templates/select.template.xml
Removed:
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/InplaceInputBaseRenderer.java
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/InplaceSelectBaseRenderer.java
Modified:
trunk/ui/input/ui/src/main/java/org/richfaces/component/AbstractInplaceSelect.java
trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/inplaceSelect.js
trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/popupList.js
trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/select.js
trunk/ui/input/ui/src/main/templates/inplaceInput.template.xml
trunk/ui/input/ui/src/main/templates/inplaceSelect.template.xml
Log:
rename inplaces base renderer, add select component ui, base renderer, template, js, ecss
Modified: trunk/ui/input/ui/src/main/java/org/richfaces/component/AbstractInplaceSelect.java
===================================================================
--- trunk/ui/input/ui/src/main/java/org/richfaces/component/AbstractInplaceSelect.java 2010-10-15 16:14:23 UTC (rev 19581)
+++ trunk/ui/input/ui/src/main/java/org/richfaces/component/AbstractInplaceSelect.java 2010-10-15 16:45:47 UTC (rev 19582)
@@ -22,10 +22,7 @@
package org.richfaces.component;
-import javax.faces.component.UISelectOne;
-
import org.richfaces.cdk.annotations.Attribute;
-import org.richfaces.cdk.annotations.EventName;
import org.richfaces.cdk.annotations.JsfComponent;
import org.richfaces.cdk.annotations.JsfRenderer;
import org.richfaces.cdk.annotations.Tag;
@@ -43,24 +40,15 @@
renderer = @JsfRenderer(type = "org.richfaces.InplaceSelectRenderer"),
tag = @Tag(name="inplaceSelect")
)
-public abstract class AbstractInplaceSelect extends UISelectOne implements InplaceComponent {
+public abstract class AbstractInplaceSelect extends AbstractSelect implements InplaceComponent {
public static final String COMPONENT_TYPE = "org.richfaces.InplaceSelect";
- public static final String COMPONENT_FAMILY = "org.richfaces.InplaceSelect";
+ public static final String COMPONENT_FAMILY = "org.richfaces.Select";
- @Attribute(defaultValue="250px")
- public abstract String getListWidth();
-
- @Attribute(defaultValue="100px")
- public abstract String getListHeight();
-
@Attribute(defaultValue="InplaceState.ready")
public abstract InplaceState getState();
- @Attribute
- public abstract String getDefaultLabel();
-
@Attribute(defaultValue="false")
public abstract boolean isOpenOnEdit();
@@ -72,47 +60,17 @@
@Attribute(defaultValue="click")
public abstract String getEditEvent();
-
- @Attribute(events=@EventName("blur"))
- public abstract String getOnblur();
- @Attribute(events=@EventName("click"))
- public abstract String getOnclick();
+ @Override
+ @Attribute(defaultValue="rf-is-opt")
+ public abstract String getItemCss();
- @Attribute(events=@EventName("ondblclick"))
- public abstract String getOndblclick();
-
- @Attribute(events=@EventName("focus"))
- public abstract String getOnfocus();
+ @Override
+ @Attribute(defaultValue="rf-is-sel")
+ public abstract String getSelectItemCss();
- @Attribute(events=@EventName("keydown"))
- public abstract String getOnkeydown();
+ @Override
+ @Attribute(defaultValue="rf-is-lst-cord")
+ public abstract String getListCss();
- @Attribute(events=@EventName("keypress"))
- public abstract String getOnkeypress();
-
- @Attribute(events=@EventName("keyup"))
- public abstract String getOnkeypup();
-
- @Attribute(events=@EventName("mousedown"))
- public abstract String getOnmousedown();
-
- @Attribute(events=@EventName("mousemove"))
- public abstract String getOnmousemove();
-
- @Attribute(events=@EventName("mouseout"))
- public abstract String getOnmouseout();
-
- @Attribute(events=@EventName("mouseover"))
- public abstract String getOnmouseover();
-
- @Attribute(events=@EventName("mouseup"))
- public abstract String getOnmouseup();
-
- @Attribute(events=@EventName("select"))
- public abstract String getOnselect();
-
- @Attribute(events=@EventName("change"))
- public abstract String getOnchange();
-
}
Added: trunk/ui/input/ui/src/main/java/org/richfaces/component/AbstractSelect.java
===================================================================
--- trunk/ui/input/ui/src/main/java/org/richfaces/component/AbstractSelect.java (rev 0)
+++ trunk/ui/input/ui/src/main/java/org/richfaces/component/AbstractSelect.java 2010-10-15 16:45:47 UTC (rev 19582)
@@ -0,0 +1,90 @@
+package org.richfaces.component;
+
+import javax.faces.component.UISelectOne;
+
+import org.richfaces.cdk.annotations.Attribute;
+import org.richfaces.cdk.annotations.EventName;
+import org.richfaces.cdk.annotations.JsfComponent;
+import org.richfaces.cdk.annotations.JsfRenderer;
+import org.richfaces.cdk.annotations.Tag;
+
+
+@JsfComponent(
+ type = AbstractSelect.COMPONENT_TYPE,
+ family = AbstractSelect.COMPONENT_FAMILY,
+ generate = "org.richfaces.component.UISelect",
+ renderer = @JsfRenderer(type = "org.richfaces.SelectRenderer"),
+ tag = @Tag(name="select")
+)
+public abstract class AbstractSelect extends UISelectOne {
+
+ public static final String COMPONENT_TYPE = "org.richfaces.Select";
+
+ public static final String COMPONENT_FAMILY = "org.richfaces.Select";
+
+ @Attribute(defaultValue="250px")
+ public abstract String getListWidth();
+
+ @Attribute(defaultValue="100px")
+ public abstract String getListHeight();
+
+ @Attribute(defaultValue="true")
+ public abstract boolean isShowButton();
+
+ @Attribute
+ public abstract String getDefaultLabel();
+
+ @Attribute(events=@EventName("blur"))
+ public abstract String getOnblur();
+
+ @Attribute(events=@EventName("click"))
+ public abstract String getOnclick();
+
+ @Attribute(events=@EventName("ondblclick"))
+ public abstract String getOndblclick();
+
+ @Attribute(events=@EventName("focus"))
+ public abstract String getOnfocus();
+
+ @Attribute(events=@EventName("keydown"))
+ public abstract String getOnkeydown();
+
+ @Attribute(events=@EventName("keypress"))
+ public abstract String getOnkeypress();
+
+ @Attribute(events=@EventName("keyup"))
+ public abstract String getOnkeypup();
+
+ @Attribute(events=@EventName("mousedown"))
+ public abstract String getOnmousedown();
+
+ @Attribute(events=@EventName("mousemove"))
+ public abstract String getOnmousemove();
+
+ @Attribute(events=@EventName("mouseout"))
+ public abstract String getOnmouseout();
+
+ @Attribute(events=@EventName("mouseover"))
+ public abstract String getOnmouseover();
+
+ @Attribute(events=@EventName("mouseup"))
+ public abstract String getOnmouseup();
+
+ @Attribute(events=@EventName("select"))
+ public abstract String getOnselect();
+
+ @Attribute(events=@EventName("change"))
+ public abstract String getOnchange();
+
+ @Attribute(defaultValue = "rf-au-opt")
+ public abstract String getItemCss();
+
+ @Attribute(defaultValue = "rf-au-sel")
+ public abstract String getSelectItemCss();
+
+ @Attribute(defaultValue = "rf-au-lst-cord")
+ public abstract String getListCss();
+
+
+
+}
Added: trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/ClientSelectItem.java
===================================================================
--- trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/ClientSelectItem.java (rev 0)
+++ trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/ClientSelectItem.java 2010-10-15 16:45:47 UTC (rev 19582)
@@ -0,0 +1,50 @@
+package org.richfaces.renderkit;
+
+import org.ajax4jsf.javascript.ScriptString;
+import org.ajax4jsf.javascript.ScriptUtils;
+
+public final class ClientSelectItem implements ScriptString {
+
+ private String clientId;
+ private String label;
+ private String convertedValue;
+
+ public ClientSelectItem(String convertedValue, String label) {
+ this(convertedValue, label, null);
+ }
+
+ public ClientSelectItem(String convertedValue, String label,
+ String clientId) {
+ super();
+ this.convertedValue = convertedValue;
+ this.label = label;
+ this.clientId = clientId;
+ }
+
+ public String getClientId() {
+ return clientId;
+ }
+
+ public void setClientId(String clientId) {
+ this.clientId = clientId;
+ }
+
+ public String getLabel() {
+ return label;
+ }
+
+ public String getConvertedValue() {
+ return convertedValue;
+ }
+
+ public void appendScript(StringBuffer functionString) {
+ functionString.append(this.toScript());
+ }
+
+ public String toScript() {
+ return "{ 'id' : " + ScriptUtils.toScript(clientId)
+ + " , 'label' : " + ScriptUtils.toScript(label)
+ + ", 'value' : " + ScriptUtils.toScript(convertedValue)
+ + "}";
+ }
+}
Deleted: trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/InplaceInputBaseRenderer.java
===================================================================
--- trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/InplaceInputBaseRenderer.java 2010-10-15 16:14:23 UTC (rev 19581)
+++ trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/InplaceInputBaseRenderer.java 2010-10-15 16:45:47 UTC (rev 19582)
@@ -1,287 +0,0 @@
-/*
- * 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.io.IOException;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.faces.application.Resource;
-import javax.faces.application.ResourceDependencies;
-import javax.faces.application.ResourceDependency;
-import javax.faces.application.ResourceHandler;
-import javax.faces.component.UIComponent;
-import javax.faces.context.FacesContext;
-import javax.faces.context.ResponseWriter;
-
-import org.ajax4jsf.javascript.JSFunction;
-import org.richfaces.component.InplaceComponent;
-import org.richfaces.component.InplaceState;
-import org.richfaces.component.util.HtmlUtil;
-
-/**
- * @author Anton Belevich
- *
- */
-@ResourceDependencies({
- @ResourceDependency(library = "javax.faces", name = "jsf.js"),
- @ResourceDependency(name = "jquery.js"),
- @ResourceDependency(name = "richfaces.js"),
- @ResourceDependency(name = "richfaces-event.js"),
- @ResourceDependency(name = "richfaces-base-component.js"),
- @ResourceDependency(library = "org.richfaces", name = "inplaceBase.js"),
- @ResourceDependency(library = "org.richfaces", name = "inplaceInput.js"),
- @ResourceDependency(library = "org.richfaces", name = "inplaceInput.ecss") })
-public class InplaceInputBaseRenderer extends InputRendererBase {
-
- public static final String OPTIONS_EDIT_EVENT = "editEvent";
-
- public static final String OPTIONS_STATE = "state";
-
- public static final String OPTIONS_EDIT_CONTAINER = "editContainer";
-
- public static final String OPTIONS_INPUT = "input";
-
- public static final String OPTIONS_FOCUS = "focusElement";
-
- public static final String OPTIONS_BUTTON_OK = "okbtn";
-
- public static final String OPTIONS_LABEL = "label";
-
- public static final String OPTIONS_DEFAULT_LABEL = "defaultLabel";
-
- public static final String OPTIONS_BUTTON_CANCEL = "cancelbtn";
-
- public static final String OPTIONS_SHOWCONTROLS = "showControls";
-
- public static final String OPTIONS_NONE_CSS = "noneCss";
-
- public static final String OPTIONS_CHANGED_CSS = "changedCss";
-
- public static final String OPTIONS_EDIT_CSS = "editCss";
-
- public static final String OPTIONS_INITIAL_VALUE = "initialValue";
-
- public static final String OPTIONS_SAVE_ON_BLUR = "saveOnBlur";
-
- private static final Map<String, ComponentAttribute> INPLACEINPUT_HANDLER_ATTRIBUTES = Collections
- .unmodifiableMap(ComponentAttribute.createMap(
- new ComponentAttribute(HtmlConstants.ONCLICK_ATTRIBUTE)
- .setEventNames("inputclick")
- .setComponentAttributeName("oninputclick"),
- new ComponentAttribute(HtmlConstants.ONDBLCLICK_ATTRIBUTE)
- .setEventNames("inputdblclick")
- .setComponentAttributeName("oninputdblclick"),
- new ComponentAttribute(HtmlConstants.ONMOUSEDOWN_ATTRIBUTE)
- .setEventNames("inputmousedown")
- .setComponentAttributeName("oninputmousedown"),
- new ComponentAttribute(HtmlConstants.ONMOUSEUP_ATTRIBUTE)
- .setEventNames("inputmouseup")
- .setComponentAttributeName("oninputmouseup"),
- new ComponentAttribute(HtmlConstants.ONMOUSEOVER_ATTRIBUTE)
- .setEventNames("inputmouseover")
- .setComponentAttributeName("oninputmouseover"),
- new ComponentAttribute(HtmlConstants.ONMOUSEMOVE_ATTRIBUTE)
- .setEventNames("inputmousemove")
- .setComponentAttributeName("oninputmousemove"),
- new ComponentAttribute(HtmlConstants.ONMOUSEOUT_ATTRIBUTE)
- .setEventNames("inputmouseout")
- .setComponentAttributeName("oninputmouseout"),
- new ComponentAttribute(HtmlConstants.ONKEYPRESS_ATTRIBUTE)
- .setEventNames("inputkeypress")
- .setComponentAttributeName("oninputkeypress"),
- new ComponentAttribute(HtmlConstants.ONKEYDOWN_ATTRIBUTE)
- .setEventNames("inputkeydown")
- .setComponentAttributeName("oninputkeydown"),
- new ComponentAttribute(HtmlConstants.ONKEYUP_ATTRIBUTE)
- .setEventNames("inputkeyup")
- .setComponentAttributeName("oninputkeyup"),
- new ComponentAttribute(HtmlConstants.ONBLUR_ATTRIBUTE)
- .setEventNames("inputblur")
- .setComponentAttributeName("oninputblur"),
- new ComponentAttribute(HtmlConstants.ONFOCUS_ATTRIBUTE)
- .setEventNames("inputfocus")
- .setComponentAttributeName("oninputfocus"),
- new ComponentAttribute(HtmlConstants.ONCHANGE_ATTRIBUTE)
- .setEventNames("change").setComponentAttributeName(
- "onchange"),
- new ComponentAttribute(HtmlConstants.ONSELECT_ATTRIBUTE)
- .setEventNames("select").setComponentAttributeName(
- "onselect")));
-
- protected void renderInputHandlers(FacesContext facesContext,
- UIComponent component) throws IOException {
- RenderKitUtils.renderPassThroughAttributesOptimized(facesContext,
- component, INPLACEINPUT_HANDLER_ATTRIBUTES);
- }
-
- public InplaceState getInplaceState(UIComponent component) {
- return ((InplaceComponent) component).getState();
- }
-
- public String getValue(FacesContext facesContext, UIComponent component) throws IOException {
- String value = getInputValue(facesContext, component);
- if (!isDisable(getInplaceState(component)) && (value == null || "".equals(value)) ) {
- value = ((InplaceComponent) component).getDefaultLabel();
- }
- return value;
- }
-
- public String getResourcePath(FacesContext context, String resourceName) {
- if (resourceName != null) {
- ResourceHandler resourceHandler = context.getApplication()
- .getResourceHandler();
- Resource resource = resourceHandler.createResource(resourceName);
- return resource.getRequestPath();
- }
- return null;
- }
-
- public String getStateStyleClass(UIComponent component,
- InplaceState inplaceState) {
- String style = getReadyStateCss();
- switch (inplaceState) {
- case edit:
- style = HtmlUtil.concatClasses(style, getEditStateCss());
- break;
-
- case changed:
- style = HtmlUtil.concatClasses(style, getChangedStateCss());
- break;
-
- case disable:
- style = getDisableStateCss();
- break;
-
- default:
- break;
- }
-
- return style;
- }
-
- public boolean isDisable(InplaceState currentState) {
- return (InplaceState.disable == currentState);
- }
-
- public String getEditStyleClass(UIComponent component,
- InplaceState inplaceState) {
- return (InplaceState.edit != inplaceState) ? HtmlUtil.concatClasses(getEditCss(), getNoneCss()) : getEditCss();
- }
-
- public String getReadyClientId(FacesContext facesContext,
- UIComponent component, InplaceState inplaceState) {
- String clientId = component.getClientId(facesContext);
- return getId(clientId, InplaceState.ready, inplaceState);
- }
-
- public String getChangedClientId(FacesContext facesContext,
- UIComponent component, InplaceState inplaceState) {
- String clientId = component.getClientId(facesContext);
- return getId(clientId, InplaceState.changed, inplaceState);
- }
-
- private String getId(String clientId, InplaceState expect,
- InplaceState current) {
- String result = clientId;
- if (expect != current) {
- result = clientId + ":" + expect;
- }
- return result;
- }
-
- public void buildScript(ResponseWriter writer, FacesContext facesContext,
- UIComponent component, Object additional) throws IOException {
- if (!(component instanceof InplaceComponent)) {
- return;
- }
-
- String scriptName = getScriptName();
- JSFunction function = new JSFunction(scriptName);
- String clientId = component.getClientId(facesContext);
- Map<String, Object> options = createInplaceComponentOptions(clientId,
- (InplaceComponent) component);
- addToOptions(facesContext, component, options, additional);
- function.addParameter(clientId);
- function.addParameter(options);
- writer.write(function.toString());
- }
-
- protected String getScriptName() {
- return "new RichFaces.ui.InplaceInput";
- }
-
- private Map<String, Object> createInplaceComponentOptions(String clientId,
- InplaceComponent inplaceComponent) {
- Map<String, Object> options = new HashMap<String, Object>();
- options.put(OPTIONS_EDIT_EVENT, inplaceComponent.getEditEvent());
- options.put(OPTIONS_STATE, inplaceComponent.getState());
- options.put(OPTIONS_NONE_CSS, getNoneCss());
- options.put(OPTIONS_CHANGED_CSS, getChangedStateCss());
- options.put(OPTIONS_EDIT_CSS, getEditStateCss());
- options.put(OPTIONS_EDIT_CONTAINER, clientId + ":edit");
- options.put(OPTIONS_INPUT, clientId + ":input");
- options.put(OPTIONS_LABEL, clientId + ":label");
- options.put(OPTIONS_FOCUS, clientId + ":focus");
- options.put(OPTIONS_DEFAULT_LABEL, inplaceComponent.getDefaultLabel());
- options.put(OPTIONS_SAVE_ON_BLUR, inplaceComponent.isSaveOnBlur());
-
- boolean showControls = inplaceComponent.isShowControls();
-
- options.put(OPTIONS_SHOWCONTROLS, showControls);
- if (showControls) {
- options.put(OPTIONS_BUTTON_OK, clientId + ":okbtn");
- options.put(OPTIONS_BUTTON_CANCEL, clientId + ":cancelbtn");
- }
- return options;
- }
-
- public void addToOptions(FacesContext facesContext, UIComponent component,
- Map<String, Object> options, Object additional) {
- // override this method if you need additional options
- }
-
- public String getReadyStateCss() {
- return "rf-ii-d-s";
- }
-
- public String getEditStateCss() {
- return "rf-ii-e-s";
- }
-
- public String getChangedStateCss() {
- return "rf-ii-c-s";
- }
-
- public String getDisableStateCss() {
- return "rf-ii-dis-s";
- }
-
- public String getEditCss() {
- return "rf-ii-edit";
- }
-
- public String getNoneCss() {
- return "rf-ii-none";
- }
-}
Added: trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/InplaceInputRendererBase.java
===================================================================
--- trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/InplaceInputRendererBase.java (rev 0)
+++ trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/InplaceInputRendererBase.java 2010-10-15 16:45:47 UTC (rev 19582)
@@ -0,0 +1,287 @@
+/*
+ * 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.io.IOException;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.faces.application.Resource;
+import javax.faces.application.ResourceDependencies;
+import javax.faces.application.ResourceDependency;
+import javax.faces.application.ResourceHandler;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+
+import org.ajax4jsf.javascript.JSFunction;
+import org.richfaces.component.InplaceComponent;
+import org.richfaces.component.InplaceState;
+import org.richfaces.component.util.HtmlUtil;
+
+/**
+ * @author Anton Belevich
+ *
+ */
+@ResourceDependencies({
+ @ResourceDependency(library = "javax.faces", name = "jsf.js"),
+ @ResourceDependency(name = "jquery.js"),
+ @ResourceDependency(name = "richfaces.js"),
+ @ResourceDependency(name = "richfaces-event.js"),
+ @ResourceDependency(name = "richfaces-base-component.js"),
+ @ResourceDependency(library = "org.richfaces", name = "inplaceBase.js"),
+ @ResourceDependency(library = "org.richfaces", name = "inplaceInput.js"),
+ @ResourceDependency(library = "org.richfaces", name = "inplaceInput.ecss") })
+public class InplaceInputRendererBase extends InputRendererBase {
+
+ public static final String OPTIONS_EDIT_EVENT = "editEvent";
+
+ public static final String OPTIONS_STATE = "state";
+
+ public static final String OPTIONS_EDIT_CONTAINER = "editContainer";
+
+ public static final String OPTIONS_INPUT = "input";
+
+ public static final String OPTIONS_FOCUS = "focusElement";
+
+ public static final String OPTIONS_BUTTON_OK = "okbtn";
+
+ public static final String OPTIONS_LABEL = "label";
+
+ public static final String OPTIONS_DEFAULT_LABEL = "defaultLabel";
+
+ public static final String OPTIONS_BUTTON_CANCEL = "cancelbtn";
+
+ public static final String OPTIONS_SHOWCONTROLS = "showControls";
+
+ public static final String OPTIONS_NONE_CSS = "noneCss";
+
+ public static final String OPTIONS_CHANGED_CSS = "changedCss";
+
+ public static final String OPTIONS_EDIT_CSS = "editCss";
+
+ public static final String OPTIONS_INITIAL_VALUE = "initialValue";
+
+ public static final String OPTIONS_SAVE_ON_BLUR = "saveOnBlur";
+
+ private static final Map<String, ComponentAttribute> INPLACEINPUT_HANDLER_ATTRIBUTES = Collections
+ .unmodifiableMap(ComponentAttribute.createMap(
+ new ComponentAttribute(HtmlConstants.ONCLICK_ATTRIBUTE)
+ .setEventNames("inputclick")
+ .setComponentAttributeName("oninputclick"),
+ new ComponentAttribute(HtmlConstants.ONDBLCLICK_ATTRIBUTE)
+ .setEventNames("inputdblclick")
+ .setComponentAttributeName("oninputdblclick"),
+ new ComponentAttribute(HtmlConstants.ONMOUSEDOWN_ATTRIBUTE)
+ .setEventNames("inputmousedown")
+ .setComponentAttributeName("oninputmousedown"),
+ new ComponentAttribute(HtmlConstants.ONMOUSEUP_ATTRIBUTE)
+ .setEventNames("inputmouseup")
+ .setComponentAttributeName("oninputmouseup"),
+ new ComponentAttribute(HtmlConstants.ONMOUSEOVER_ATTRIBUTE)
+ .setEventNames("inputmouseover")
+ .setComponentAttributeName("oninputmouseover"),
+ new ComponentAttribute(HtmlConstants.ONMOUSEMOVE_ATTRIBUTE)
+ .setEventNames("inputmousemove")
+ .setComponentAttributeName("oninputmousemove"),
+ new ComponentAttribute(HtmlConstants.ONMOUSEOUT_ATTRIBUTE)
+ .setEventNames("inputmouseout")
+ .setComponentAttributeName("oninputmouseout"),
+ new ComponentAttribute(HtmlConstants.ONKEYPRESS_ATTRIBUTE)
+ .setEventNames("inputkeypress")
+ .setComponentAttributeName("oninputkeypress"),
+ new ComponentAttribute(HtmlConstants.ONKEYDOWN_ATTRIBUTE)
+ .setEventNames("inputkeydown")
+ .setComponentAttributeName("oninputkeydown"),
+ new ComponentAttribute(HtmlConstants.ONKEYUP_ATTRIBUTE)
+ .setEventNames("inputkeyup")
+ .setComponentAttributeName("oninputkeyup"),
+ new ComponentAttribute(HtmlConstants.ONBLUR_ATTRIBUTE)
+ .setEventNames("inputblur")
+ .setComponentAttributeName("oninputblur"),
+ new ComponentAttribute(HtmlConstants.ONFOCUS_ATTRIBUTE)
+ .setEventNames("inputfocus")
+ .setComponentAttributeName("oninputfocus"),
+ new ComponentAttribute(HtmlConstants.ONCHANGE_ATTRIBUTE)
+ .setEventNames("change").setComponentAttributeName(
+ "onchange"),
+ new ComponentAttribute(HtmlConstants.ONSELECT_ATTRIBUTE)
+ .setEventNames("select").setComponentAttributeName(
+ "onselect")));
+
+ protected void renderInputHandlers(FacesContext facesContext,
+ UIComponent component) throws IOException {
+ RenderKitUtils.renderPassThroughAttributesOptimized(facesContext,
+ component, INPLACEINPUT_HANDLER_ATTRIBUTES);
+ }
+
+ public InplaceState getInplaceState(UIComponent component) {
+ return ((InplaceComponent) component).getState();
+ }
+
+ public String getValue(FacesContext facesContext, UIComponent component) throws IOException {
+ String value = getInputValue(facesContext, component);
+ if (!isDisable(getInplaceState(component)) && (value == null || "".equals(value)) ) {
+ value = ((InplaceComponent) component).getDefaultLabel();
+ }
+ return value;
+ }
+
+ public String getResourcePath(FacesContext context, String resourceName) {
+ if (resourceName != null) {
+ ResourceHandler resourceHandler = context.getApplication()
+ .getResourceHandler();
+ Resource resource = resourceHandler.createResource(resourceName);
+ return resource.getRequestPath();
+ }
+ return null;
+ }
+
+ public String getStateStyleClass(UIComponent component,
+ InplaceState inplaceState) {
+ String style = getReadyStateCss();
+ switch (inplaceState) {
+ case edit:
+ style = HtmlUtil.concatClasses(style, getEditStateCss());
+ break;
+
+ case changed:
+ style = HtmlUtil.concatClasses(style, getChangedStateCss());
+ break;
+
+ case disable:
+ style = getDisableStateCss();
+ break;
+
+ default:
+ break;
+ }
+
+ return style;
+ }
+
+ public boolean isDisable(InplaceState currentState) {
+ return (InplaceState.disable == currentState);
+ }
+
+ public String getEditStyleClass(UIComponent component,
+ InplaceState inplaceState) {
+ return (InplaceState.edit != inplaceState) ? HtmlUtil.concatClasses(getEditCss(), getNoneCss()) : getEditCss();
+ }
+
+ public String getReadyClientId(FacesContext facesContext,
+ UIComponent component, InplaceState inplaceState) {
+ String clientId = component.getClientId(facesContext);
+ return getId(clientId, InplaceState.ready, inplaceState);
+ }
+
+ public String getChangedClientId(FacesContext facesContext,
+ UIComponent component, InplaceState inplaceState) {
+ String clientId = component.getClientId(facesContext);
+ return getId(clientId, InplaceState.changed, inplaceState);
+ }
+
+ private String getId(String clientId, InplaceState expect,
+ InplaceState current) {
+ String result = clientId;
+ if (expect != current) {
+ result = clientId + ":" + expect;
+ }
+ return result;
+ }
+
+ public void buildScript(ResponseWriter writer, FacesContext facesContext,
+ UIComponent component, Object additional) throws IOException {
+ if (!(component instanceof InplaceComponent)) {
+ return;
+ }
+
+ String scriptName = getScriptName();
+ JSFunction function = new JSFunction(scriptName);
+ String clientId = component.getClientId(facesContext);
+ Map<String, Object> options = createInplaceComponentOptions(clientId,
+ (InplaceComponent) component);
+ addToOptions(facesContext, component, options, additional);
+ function.addParameter(clientId);
+ function.addParameter(options);
+ writer.write(function.toString());
+ }
+
+ protected String getScriptName() {
+ return "new RichFaces.ui.InplaceInput";
+ }
+
+ private Map<String, Object> createInplaceComponentOptions(String clientId,
+ InplaceComponent inplaceComponent) {
+ Map<String, Object> options = new HashMap<String, Object>();
+ options.put(OPTIONS_EDIT_EVENT, inplaceComponent.getEditEvent());
+ options.put(OPTIONS_STATE, inplaceComponent.getState());
+ options.put(OPTIONS_NONE_CSS, getNoneCss());
+ options.put(OPTIONS_CHANGED_CSS, getChangedStateCss());
+ options.put(OPTIONS_EDIT_CSS, getEditStateCss());
+ options.put(OPTIONS_EDIT_CONTAINER, clientId + ":edit");
+ options.put(OPTIONS_INPUT, clientId + ":input");
+ options.put(OPTIONS_LABEL, clientId + ":label");
+ options.put(OPTIONS_FOCUS, clientId + ":focus");
+ options.put(OPTIONS_DEFAULT_LABEL, inplaceComponent.getDefaultLabel());
+ options.put(OPTIONS_SAVE_ON_BLUR, inplaceComponent.isSaveOnBlur());
+
+ boolean showControls = inplaceComponent.isShowControls();
+
+ options.put(OPTIONS_SHOWCONTROLS, showControls);
+ if (showControls) {
+ options.put(OPTIONS_BUTTON_OK, clientId + ":okbtn");
+ options.put(OPTIONS_BUTTON_CANCEL, clientId + ":cancelbtn");
+ }
+ return options;
+ }
+
+ public void addToOptions(FacesContext facesContext, UIComponent component,
+ Map<String, Object> options, Object additional) {
+ // override this method if you need additional options
+ }
+
+ public String getReadyStateCss() {
+ return "rf-ii-d-s";
+ }
+
+ public String getEditStateCss() {
+ return "rf-ii-e-s";
+ }
+
+ public String getChangedStateCss() {
+ return "rf-ii-c-s";
+ }
+
+ public String getDisableStateCss() {
+ return "rf-ii-dis-s";
+ }
+
+ public String getEditCss() {
+ return "rf-ii-edit";
+ }
+
+ public String getNoneCss() {
+ return "rf-ii-none";
+ }
+}
Deleted: trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/InplaceSelectBaseRenderer.java
===================================================================
--- trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/InplaceSelectBaseRenderer.java 2010-10-15 16:14:23 UTC (rev 19581)
+++ trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/InplaceSelectBaseRenderer.java 2010-10-15 16:45:47 UTC (rev 19582)
@@ -1,266 +0,0 @@
-/*
- * 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.io.IOException;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-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.context.ResponseWriter;
-import javax.faces.model.SelectItem;
-
-import org.ajax4jsf.javascript.ScriptString;
-import org.ajax4jsf.javascript.ScriptUtils;
-import org.richfaces.component.AbstractInplaceSelect;
-import org.richfaces.component.util.InputUtils;
-import org.richfaces.component.util.SelectUtils;
-
-/**
- * @author Anton Belevich
- *
- */
-
-@ResourceDependencies({
- @ResourceDependency(library = "javax.faces", name = "jsf.js"),
- @ResourceDependency(name = "jquery.js"),
- @ResourceDependency(name = "jquery.position.js"),
- @ResourceDependency(name = "richfaces.js"),
- @ResourceDependency(name = "jquery.position.js"),
- @ResourceDependency(name = "richfaces-event.js"),
- @ResourceDependency(name = "richfaces-base-component.js"),
- @ResourceDependency(name = "richfaces-selection.js"),
- @ResourceDependency(library = "org.richfaces", name = "inplaceBase.js"),
- @ResourceDependency(library = "org.richfaces", name = "popup.js"),
- @ResourceDependency(library = "org.richfaces", name = "popupList.js"),
- @ResourceDependency(library = "org.richfaces", name = "selectList.js"),
- @ResourceDependency(library = "org.richfaces", name = "inplaceInput.js"),
- @ResourceDependency(library = "org.richfaces", name = "inplaceSelect.js"),
- @ResourceDependency(library = "org.richfaces", name = "inplaceSelect.ecss") })
-public class InplaceSelectBaseRenderer extends InplaceInputBaseRenderer {
-
- public static final String OPTIONS_ITEM_CLASS = "itemCss";
-
- public static final String OPTIONS_SELECT_ITEM_CLASS = "selectItemCss";
-
- public static final String OPTIONS_LIST_CORD = "listCord";
-
- public static final String OPTIONS_ITEMS_CORD = "itemsCord";
-
- public static final String OPTIONS_SELECT_ITEMS = "selectItems";
-
- public static final String OPTIONS_SELECT_ITEM_VALUE_INPUT = "selValueInput";
-
- public static final String OPTIONS_VISIBLE = "visible";
-
- protected static final class ClientSelectItem implements ScriptString {
-
- private String clientId;
- private String label;
- private String convertedValue;
-
- public ClientSelectItem(String convertedValue, String label) {
- this(convertedValue, label, null);
- }
-
- public ClientSelectItem(String convertedValue, String label,
- String clientId) {
- super();
- this.convertedValue = convertedValue;
- this.label = label;
- this.clientId = clientId;
- }
-
- public String getClientId() {
- return clientId;
- }
-
- public void setClientId(String clientId) {
- this.clientId = clientId;
- }
-
- public String getLabel() {
- return label;
- }
-
- public String getConvertedValue() {
- return convertedValue;
- }
-
- public void appendScript(StringBuffer functionString) {
- functionString.append(this.toScript());
- }
-
- public String toScript() {
- return "{ 'id' : " + ScriptUtils.toScript(clientId)
- + " , 'label' : " + ScriptUtils.toScript(label)
- + ", 'value' : " + ScriptUtils.toScript(convertedValue)
- + "}";
- }
- }
-
-
- private static final Map<String, ComponentAttribute> INPLACESELECT_HANDLER_ATTRIBUTES = Collections
- .unmodifiableMap(ComponentAttribute.createMap(
- new ComponentAttribute(HtmlConstants.ONCHANGE_ATTRIBUTE).setEventNames("change").
- setComponentAttributeName("onchange"),
- new ComponentAttribute(HtmlConstants.ONSELECT_ATTRIBUTE).setEventNames("select").
- setComponentAttributeName("onselect")
- ));
-
- @Override
- protected String getScriptName() {
- return "new RichFaces.ui.InplaceSelect";
- }
-
- public List<ClientSelectItem> getConvertedSelectItems(
- FacesContext facesContext, UIComponent component) {
- AbstractInplaceSelect inplaceSelect = (AbstractInplaceSelect) component;
- List<SelectItem> selectItems = SelectUtils.getSelectItems(facesContext,
- inplaceSelect);
- List<ClientSelectItem> clientSelectItems = new ArrayList<InplaceSelectBaseRenderer.ClientSelectItem>();
- for (SelectItem selectItem : selectItems) {
- String convertedStringValue = InputUtils.getConvertedStringValue(
- facesContext, inplaceSelect, selectItem.getValue());
- String label = selectItem.getLabel();
- clientSelectItems.add(new ClientSelectItem(convertedStringValue,
- label));
- }
- return clientSelectItems;
- }
-
- @Override
- protected void renderInputHandlers(FacesContext facesContext, UIComponent component) throws IOException {
- RenderKitUtils.renderPassThroughAttributesOptimized(facesContext, component, INPLACESELECT_HANDLER_ATTRIBUTES);
- }
-
- @Override
- public void addToOptions(FacesContext facesContext, UIComponent component,
- Map<String, Object> options, Object additional) {
- options.put(OPTIONS_ITEM_CLASS, "rf-is-opt");
- options.put(OPTIONS_SELECT_ITEM_CLASS, "rf-is-sel");
- String clientId = component.getClientId(facesContext);
- options.put(OPTIONS_LIST_CORD, clientId + "List");
- options.put(OPTIONS_ITEMS_CORD, clientId + "Items");
- options.put(OPTIONS_SELECT_ITEMS, additional);
- options.put(OPTIONS_SELECT_ITEM_VALUE_INPUT, clientId + "selValue");
- options.put(OPTIONS_VISIBLE, component.getAttributes().get("openOnEdit"));
- }
-
- public void encodeOptions(FacesContext facesContext, UIComponent component,
- List<ClientSelectItem> clientSelectItems) throws IOException {
- AbstractInplaceSelect inplaceSelect = (AbstractInplaceSelect) component;
- if (clientSelectItems != null && !clientSelectItems.isEmpty()) {
- ResponseWriter writer = facesContext.getResponseWriter();
- String clientId = component.getClientId(facesContext);
- int i = 0;
- for (ClientSelectItem clientSelectItem : clientSelectItems) {
- String itemClientId = clientId + "Item" + (i++);
- clientSelectItem.setClientId(itemClientId);
-
- writer.startElement(HtmlConstants.SPAN_ELEM, inplaceSelect);
- writer.writeAttribute(HtmlConstants.ID_ATTRIBUTE, itemClientId,
- null);
- writer.writeAttribute(HtmlConstants.CLASS_ATTRIBUTE,
- getOptionCss(), null);
-
- String label = clientSelectItem.getLabel();
- if (label != null && label.trim().length() > 0) {
- writer.writeText(label, null);
- } else {
- writer.write("\u00a0");
- }
- writer.endElement(HtmlConstants.SPAN_ELEM);
- }
- }
- }
-
- public String getSelectLabel(FacesContext facesContext,
- UIComponent component) {
- AbstractInplaceSelect select = (AbstractInplaceSelect) component;
- String label = getSelectInputLabel(facesContext, select);
- if (!isDisable(getInplaceState(component)) && (label == null)) {
- label = select.getDefaultLabel();
- }
- return label;
- }
-
- public String getSelectInputLabel(FacesContext facesContext,
- UIComponent component) {
- AbstractInplaceSelect select = (AbstractInplaceSelect) component;
- Object value = select.getSubmittedValue();
- if (value == null) {
- value = select.getValue();
- if (value != null) {
- List<SelectItem> items = SelectUtils.getSelectItems(
- facesContext, component);
- for (SelectItem item : items) {
- if (value.equals(item.getValue())) {
- value = item.getLabel();
- }
- }
- }
- }
-
- return (String) value;
- }
-
- public String getListStyles(FacesContext facesContext, UIComponent component) {
- AbstractInplaceSelect inplaceSelect = (AbstractInplaceSelect) component;
- return inplaceSelect.isOpenOnEdit() ? "" : "display: none";
- }
-
- public String getReadyStateCss() {
- return "rf-is-d-s";
- }
-
- public String getEditStateCss() {
- return "rf-is-e-s";
- }
-
- public String getChangedStateCss() {
- return "rf-is-c-s";
- }
-
- public String getDisableStateCss() {
- return "rf-is-dis-s";
- }
-
- public String getEditCss() {
- return "rf-is-edit";
- }
-
- public String getNoneCss() {
- return "rf-is-none";
- }
-
- public String getOptionCss() {
- return "rf-is-opt rf-is-fnt";
- }
-
-}
Added: trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/InplaceSelectRendererBase.java
===================================================================
--- trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/InplaceSelectRendererBase.java (rev 0)
+++ trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/InplaceSelectRendererBase.java 2010-10-15 16:45:47 UTC (rev 19582)
@@ -0,0 +1,147 @@
+/*
+ * 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.io.IOException;
+import java.util.Collections;
+import java.util.List;
+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 org.richfaces.component.AbstractInplaceSelect;
+
+/**
+ * @author Anton Belevich
+ *
+ */
+
+@ResourceDependencies({
+ @ResourceDependency(library = "javax.faces", name = "jsf.js"),
+ @ResourceDependency(name = "jquery.js"),
+ @ResourceDependency(name = "jquery.position.js"),
+ @ResourceDependency(name = "richfaces.js"),
+ @ResourceDependency(name = "jquery.position.js"),
+ @ResourceDependency(name = "richfaces-event.js"),
+ @ResourceDependency(name = "richfaces-base-component.js"),
+ @ResourceDependency(name = "richfaces-selection.js"),
+ @ResourceDependency(library = "org.richfaces", name = "inplaceBase.js"),
+ @ResourceDependency(library = "org.richfaces", name = "popup.js"),
+ @ResourceDependency(library = "org.richfaces", name = "popupList.js"),
+ @ResourceDependency(library = "org.richfaces", name = "selectList.js"),
+ @ResourceDependency(library = "org.richfaces", name = "inplaceInput.js"),
+ @ResourceDependency(library = "org.richfaces", name = "inplaceSelect.js"),
+ @ResourceDependency(library = "org.richfaces", name = "inplaceSelect.ecss") })
+public class InplaceSelectRendererBase extends InplaceInputRendererBase {
+
+
+ public static final String OPTION_LIST_ITEMS = "items";
+
+ public static final String OPTIONS_SELECT_ITEM_VALUE_INPUT = "selValueInput";
+
+ public static final String OPTIONS_VISIBLE = "visible";
+
+ private static final Map<String, ComponentAttribute> INPLACESELECT_HANDLER_ATTRIBUTES = Collections.unmodifiableMap(ComponentAttribute.createMap(
+ new ComponentAttribute(HtmlConstants.ONCHANGE_ATTRIBUTE).setEventNames("change").
+ setComponentAttributeName("onchange"),
+ new ComponentAttribute(HtmlConstants.ONSELECT_ATTRIBUTE).setEventNames("select").
+ setComponentAttributeName("onselect")
+ ));
+
+ @Override
+ protected String getScriptName() {
+ return "new RichFaces.ui.InplaceSelect";
+ }
+
+ public List<ClientSelectItem> getConvertedSelectItems(FacesContext facesContext, UIComponent component) {
+ return SelectHelper.getConvertedSelectItems(facesContext, component);
+ }
+
+ public void encodeItems(FacesContext facesContext, UIComponent component, List<ClientSelectItem> clientSelectItems) throws IOException {
+ SelectHelper.encodeItems(facesContext, component, clientSelectItems, HtmlConstants.SPAN_ELEM);
+ }
+
+ @Override
+ protected void renderInputHandlers(FacesContext facesContext, UIComponent component) throws IOException {
+ RenderKitUtils.renderPassThroughAttributesOptimized(facesContext, component, INPLACESELECT_HANDLER_ATTRIBUTES);
+ }
+
+ public String getSelectInputLabel(FacesContext facesContext, UIComponent component) {
+ return SelectHelper.getSelectInputLabel(facesContext, component);
+ }
+
+ @Override
+ public void addToOptions(FacesContext facesContext, UIComponent component, Map<String, Object> options, Object additional) {
+ options.put(PopupConstants.OPTIONS_ITEM_CLASS, "rf-is-opt");
+ options.put(PopupConstants.OPTIONS_SELECT_ITEM_CLASS, "rf-is-sel");
+ options.put(OPTION_LIST_ITEMS, additional);
+
+ String clientId = component.getClientId(facesContext);
+ options.put(PopupConstants.OPTIONS_LIST_CORD, clientId + "List");
+ options.put(PopupConstants.OPTIONS_LIST_CLASS, component.getAttributes().get("listCss"));
+
+ options.put(OPTIONS_SELECT_ITEM_VALUE_INPUT, clientId + "selValue");
+ options.put(OPTIONS_VISIBLE, component.getAttributes().get("openOnEdit"));
+ }
+
+ public String getSelectLabel(FacesContext facesContext, UIComponent component) {
+ AbstractInplaceSelect select = (AbstractInplaceSelect) component;
+ String label = getSelectInputLabel(facesContext, select);
+ if (!isDisable(getInplaceState(component)) && (label == null)) {
+ label = select.getDefaultLabel();
+ }
+ return label;
+ }
+
+ public String getListStyles(FacesContext facesContext, UIComponent component) {
+ AbstractInplaceSelect inplaceSelect = (AbstractInplaceSelect) component;
+ return inplaceSelect.isOpenOnEdit() ? "" : "display: none";
+ }
+
+ public String getReadyStateCss() {
+ return "rf-is-d-s";
+ }
+
+ public String getEditStateCss() {
+ return "rf-is-e-s";
+ }
+
+ public String getChangedStateCss() {
+ return "rf-is-c-s";
+ }
+
+ public String getDisableStateCss() {
+ return "rf-is-dis-s";
+ }
+
+ public String getEditCss() {
+ return "rf-is-edit";
+ }
+
+ public String getNoneCss() {
+ return "rf-is-none";
+ }
+}
Added: trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/PopupConstants.java
===================================================================
--- trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/PopupConstants.java (rev 0)
+++ trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/PopupConstants.java 2010-10-15 16:45:47 UTC (rev 19582)
@@ -0,0 +1,16 @@
+package org.richfaces.renderkit;
+
+/**
+ * @author abelevich
+ *
+ */
+public interface PopupConstants {
+
+ public static final String OPTIONS_ITEM_CLASS = "itemCss";
+
+ public static final String OPTIONS_SELECT_ITEM_CLASS = "selectItemCss";
+
+ public static final String OPTIONS_LIST_CLASS = "listCss";
+
+ public static final String OPTIONS_LIST_CORD = "list";
+}
Added: trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/SelectHelper.java
===================================================================
--- trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/SelectHelper.java (rev 0)
+++ trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/SelectHelper.java 2010-10-15 16:45:47 UTC (rev 19582)
@@ -0,0 +1,120 @@
+package org.richfaces.renderkit;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+import javax.faces.model.SelectItem;
+
+import org.richfaces.component.AbstractSelect;
+import org.richfaces.component.util.InputUtils;
+import org.richfaces.component.util.SelectUtils;
+
+/**
+ * @author abelevich
+ *
+ */
+public final class SelectHelper {
+
+ public static final Map<String, ComponentAttribute> SELECT_LIST_HANDLER_ATTRIBUTES = Collections
+ .unmodifiableMap(ComponentAttribute.createMap(
+ new ComponentAttribute(HtmlConstants.ONCLICK_ATTRIBUTE)
+ .setEventNames("listclick")
+ .setComponentAttributeName("onlistclick"),
+ new ComponentAttribute(HtmlConstants.ONDBLCLICK_ATTRIBUTE)
+ .setEventNames("listdblclick")
+ .setComponentAttributeName("onlistdblclick"),
+ new ComponentAttribute(HtmlConstants.ONMOUSEDOWN_ATTRIBUTE)
+ .setEventNames("listmousedown")
+ .setComponentAttributeName("onlistmousedown"),
+ new ComponentAttribute(HtmlConstants.ONMOUSEUP_ATTRIBUTE)
+ .setEventNames("listmouseup")
+ .setComponentAttributeName("onlistmouseup"),
+ new ComponentAttribute(HtmlConstants.ONMOUSEOVER_ATTRIBUTE)
+ .setEventNames("listmouseover")
+ .setComponentAttributeName("onlistmouseover"),
+ new ComponentAttribute(HtmlConstants.ONMOUSEMOVE_ATTRIBUTE)
+ .setEventNames("listmousemove")
+ .setComponentAttributeName("onlistmousemove"),
+ new ComponentAttribute(HtmlConstants.ONMOUSEOUT_ATTRIBUTE)
+ .setEventNames("listmouseout")
+ .setComponentAttributeName("onlistmouseout"),
+ new ComponentAttribute(HtmlConstants.ONKEYPRESS_ATTRIBUTE)
+ .setEventNames("listkeypress")
+ .setComponentAttributeName("onlistkeypress"),
+ new ComponentAttribute(HtmlConstants.ONKEYDOWN_ATTRIBUTE)
+ .setEventNames("listkeydown")
+ .setComponentAttributeName("onlistkeydown"),
+ new ComponentAttribute(HtmlConstants.ONKEYUP_ATTRIBUTE)
+ .setEventNames("listkeyup")
+ .setComponentAttributeName("onlistkeyup")
+ ));
+
+ private SelectHelper() {
+ }
+
+ public static List<ClientSelectItem> getConvertedSelectItems(FacesContext facesContext, UIComponent component) {
+ AbstractSelect select = (AbstractSelect) component;
+ List<SelectItem> selectItems = SelectUtils.getSelectItems(facesContext, select);
+ List<ClientSelectItem> clientSelectItems = new ArrayList<ClientSelectItem>();
+
+ for (SelectItem selectItem : selectItems) {
+ String convertedStringValue = InputUtils.getConvertedStringValue(facesContext, select, selectItem.getValue());
+ String label = selectItem.getLabel();
+ clientSelectItems.add(new ClientSelectItem(convertedStringValue,label));
+ }
+ return clientSelectItems;
+ }
+
+ public static void encodeItems(FacesContext facesContext, UIComponent component,
+ List<ClientSelectItem> clientSelectItems, String itemHtmlElement) throws IOException {
+ AbstractSelect select = (AbstractSelect) component;
+ if (clientSelectItems != null && !clientSelectItems.isEmpty()) {
+ ResponseWriter writer = facesContext.getResponseWriter();
+ String clientId = component.getClientId(facesContext);
+ int i = 0;
+ for (ClientSelectItem clientSelectItem : clientSelectItems) {
+ String itemClientId = clientId + "Item" + (i++);
+ clientSelectItem.setClientId(itemClientId);
+
+ writer.startElement(itemHtmlElement, select);
+ writer.writeAttribute(HtmlConstants.ID_ATTRIBUTE, itemClientId,
+ null);
+ writer.writeAttribute(HtmlConstants.CLASS_ATTRIBUTE, select.getItemCss(), null);
+
+ String label = clientSelectItem.getLabel();
+ if (label != null && label.trim().length() > 0) {
+ writer.writeText(label, null);
+ } else {
+ writer.write("\u00a0");
+ }
+ writer.endElement(itemHtmlElement);
+ }
+ }
+ }
+
+ public static String getSelectInputLabel(FacesContext facesContext, UIComponent component) {
+ AbstractSelect select = (AbstractSelect) component;
+ Object value = select.getSubmittedValue();
+ if (value == null) {
+ value = select.getValue();
+ if (value != null) {
+ List<SelectItem> items = SelectUtils.getSelectItems(
+ facesContext, component);
+ for (SelectItem item : items) {
+ if (value.equals(item.getValue())) {
+ value = item.getLabel();
+ }
+ }
+ }
+ }
+
+ return (String) value;
+ }
+
+}
Added: trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/SelectRendererBase.java
===================================================================
--- trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/SelectRendererBase.java (rev 0)
+++ trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/SelectRendererBase.java 2010-10-15 16:45:47 UTC (rev 19582)
@@ -0,0 +1,93 @@
+package org.richfaces.renderkit;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.List;
+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.context.ResponseWriter;
+
+import org.ajax4jsf.javascript.JSFunction;
+import org.richfaces.component.AbstractSelect;
+
+@ResourceDependencies({ @ResourceDependency(library = "javax.faces", name = "jsf.js"),
+ @ResourceDependency(name = "jquery.js"), @ResourceDependency(name = "jquery.position.js"),
+ @ResourceDependency(name = "richfaces.js"), @ResourceDependency(name = "jquery.position.js"),
+ @ResourceDependency(name = "richfaces-event.js"), @ResourceDependency(name = "richfaces-base-component.js"),
+ @ResourceDependency(name = "richfaces-selection.js"),
+ @ResourceDependency(library = "org.richfaces", name = "popup.js"),
+ @ResourceDependency(library = "org.richfaces", name = "popupList.js"),
+ @ResourceDependency(library = "org.richfaces", name = "selectList.js"),
+ @ResourceDependency(library = "org.richfaces", name = "select.js"),
+ @ResourceDependency(library = "org.richfaces", name = "select.ecss") })
+public class SelectRendererBase extends InputRendererBase {
+
+ //TODO: move to SelectHelper <!--
+ public static final String OPTION_SHOWCONTROL = "showControl";
+
+ public static final String OPTIONS_SELECT_ITEM_VALUE_INPUT = "selValueInput";
+
+ public static final String OPTION_LIST_ITEMS = "items";
+ // -->
+
+ public void renderListHandlers(FacesContext facesContext, UIComponent component) throws IOException {
+ RenderKitUtils.renderPassThroughAttributesOptimized(facesContext, component, SelectHelper.SELECT_LIST_HANDLER_ATTRIBUTES);
+ }
+
+ public List<ClientSelectItem> getConvertedSelectItems(FacesContext facesContext, UIComponent component) {
+ return SelectHelper.getConvertedSelectItems(facesContext, component);
+ }
+
+ public String getSelectInputLabel(FacesContext facesContext, UIComponent component) {
+ return SelectHelper.getSelectInputLabel(facesContext, component);
+ }
+
+ public void encodeItems(FacesContext facesContext, UIComponent component, List<ClientSelectItem> clientSelectItems)
+ throws IOException {
+ SelectHelper.encodeItems(facesContext, component, clientSelectItems, HtmlConstants.DIV_ELEM);
+ }
+
+ public void buildScript(ResponseWriter writer, FacesContext facesContext, UIComponent component, List<ClientSelectItem> selectItems) throws IOException {
+ if (!(component instanceof AbstractSelect)) {
+ return;
+ }
+
+ AbstractSelect abstractSelect = (AbstractSelect)component;
+ String scriptName = getScriptName();
+ JSFunction function = new JSFunction(scriptName);
+
+ String clientId = abstractSelect.getClientId(facesContext);
+ Map<String, Object> options = new HashMap<String, Object>();
+ options.put(OPTION_SHOWCONTROL, abstractSelect.isShowButton());
+ options.put(OPTION_LIST_ITEMS, selectItems);
+ options.put(PopupConstants.OPTIONS_ITEM_CLASS, abstractSelect.getItemCss());
+ options.put(PopupConstants.OPTIONS_SELECT_ITEM_CLASS, abstractSelect.getSelectItemCss());
+ options.put(PopupConstants.OPTIONS_LIST_CLASS, abstractSelect.getListCss());
+ options.put(PopupConstants.OPTIONS_LIST_CORD, clientId + "List");
+
+ function.addParameter(clientId);
+ function.addParameter(options);
+
+ writer.write(function.toString());
+ }
+
+ public String getValue(FacesContext facesContext, UIComponent component) throws IOException {
+ String value = getInputValue(facesContext, component);
+ if (value == null || "".equals(value)) {
+ value = ((AbstractSelect) component).getDefaultLabel();
+ }
+ return value;
+ }
+
+ protected String getScriptName() {
+ return "new RichFaces.ui.Select";
+ }
+
+ public String getListStyles(FacesContext facesContext, UIComponent component) {
+ return "";
+ }
+}
Modified: trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/inplaceSelect.js
===================================================================
--- trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/inplaceSelect.js 2010-10-15 16:14:23 UTC (rev 19581)
+++ trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/inplaceSelect.js 2010-10-15 16:45:47 UTC (rev 19582)
@@ -7,9 +7,9 @@
options['attachTo'] = id;
options['attachToBody'] = true;
- this.select = new rf.ui.SelectList(options.listCord, this, options);
+ this.popupList = new rf.ui.SelectList(options.list, this, options);
- this.selectItems = options.selectItems;
+ this.items = options.items;
this.selValueInput = $(document.getElementById(options.selValueInput));
this.openPopup = false;
@@ -34,7 +34,7 @@
onshow: function() {
if(this.openPopup) {
- this.select.show();
+ this.popupList.show();
}
if(!this.openPopup) {
@@ -45,7 +45,7 @@
},
onhide: function() {
- this.select.hide();
+ this.popupList.hide();
this.openPopup = false;
},
@@ -56,14 +56,14 @@
var label = this.getItemLabel(key);
this.setValue(label);
- this.select.hide();
+ this.popupList.hide();
this.openPopup = false;
this.__setInputFocus();
},
getItemValue: function(key) {
- for(var i in this.selectItems) {
- var item = this.selectItems[i];
+ for(var i in this.items) {
+ var item = this.items[i];
if(item && item.id == key) {
return item.value;
}
@@ -75,8 +75,8 @@
},
getItemLabel: function(key) {
- for(var i in this.selectItems) {
- var item = this.selectItems[i];
+ for(var i in this.items) {
+ var item = this.items[i];
if(item && item.id == key) {
return item.label;
}
@@ -93,23 +93,23 @@
code = e.which;
}
- if(this.select.isVisible()) {
+ if(this.popupList.isVisible()) {
switch(code) {
case rf.KEYS.DOWN:
e.preventDefault();
- this.select.__selectNext();
+ this.popupList.__selectNext();
this.__setInputFocus();
break;
case rf.KEYS.UP:
e.preventDefault();
- this.select.__selectPrev();
+ this.popupList.__selectPrev();
this.__setInputFocus();
break;
case rf.KEYS.RETURN:
e.preventDefault();
- this.select.__selectCurrent();
+ this.popupList.__selectCurrent();
this.__setInputFocus();
return false;
break;
@@ -118,19 +118,18 @@
$super.__keydownHandler.call(this,e);
- },
+ },
+
+ __isButton: function(target) {
+
+ },
__blurHandler: function(e) {
var target = $(e.originalEvent.explicitOriginalTarget);
- if(!this.__isPopupList(target)) {
+ if(!this.popupList.isPopupList(target)) {
$super.__blurHandler.call(this,e);
}
return false;
- },
-
- __isPopupList: function(target) {
- var parentId = target.parents(".rf-is-lst-cord").attr("id");
- return (parentId && (parentId == this.select.getId()));
}
}
Modified: trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/popupList.js
===================================================================
--- trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/popupList.js 2010-10-15 16:14:23 UTC (rev 19581)
+++ trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/popupList.js 2010-10-15 16:45:47 UTC (rev 19582)
@@ -7,7 +7,7 @@
this.selectListener = listener;
this.selectItemCss = options.selectItemCss;
this.itemCss = options.itemCss;
-
+ this.listCss = options.listCss;
this.index = -1;
this.__updateItemsList();
};
@@ -43,6 +43,11 @@
}
},
+ isPopupList: function(target) {
+ var parentId = target.parents("." + this.listCss).attr("id");
+ return (parentId && (parentId == this.getId()));
+ },
+
__updateItemsList: function () {
this.items = this.popup.find("."+this.itemCss);
},
@@ -121,7 +126,8 @@
__getItems: function () {
return this.items;
- }
+ }
+
}
})());
Added: trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/select.ecss
===================================================================
--- trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/select.ecss (rev 0)
+++ trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/select.ecss 2010-10-15 16:45:47 UTC (rev 19582)
@@ -0,0 +1,144 @@
+
+.rf-au-inp.rf-au-fnt, .rf-au-opt.rf-au-fnt{
+ color: '#{richSkin.generalTextColor}';
+ font-size: '#{richSkin.generalSizeFont}';
+ font-family: '#{richSkin.generalFamilyFont}';
+}
+
+input.rf-au-inp {
+ border-width: 0px;
+ background: none;
+ width: 100%;
+}
+
+.rf-au-fld{
+ width: 200px;
+ position: inline-block;
+ border-width: 1px;
+ border-style: solid;
+ border-color: '#{richSkin.panelBorderColor}';
+ display: inline-block;
+ background-image: "url(#{resource['org.richfaces.renderkit.html.images.AutocompleteFieldGradient']})";
+ background-repeat: repeat-x;
+ background-position: top left;
+ background-color: '#{richSkin.controlBackgroundColor}';
+}
+
+.rf-au-btn{
+ background-image: "url(#{resource['org.richfaces.renderkit.html.images.AutocompleteButtonGradient']})";
+ background-repeat: repeat-x;
+ background-position: top left;
+ background-color: '#{richSkin.headerBackgroundColor}';
+ text-align: center;
+ border-left-style: solid;
+ border-left-width: 1px;
+ border-left-color: '#{richSkin.panelBorderColor}';
+ width: 15px;
+ position: absolute;
+ top: 0px;
+ right: 0px;
+ height: 200px;
+ padding-top: 1px
+}
+
+.rf-au-btn-arrow{
+ background-position: center;
+ background-repeat: no-repeat;
+ background-image: "url(#{resource['org.richfaces:combo_down_button.gif']})";
+ cursor: pointer;
+ width: 15px;
+ height: 15px;
+}
+
+.rf-au-lst-cord{
+ position: absolute;
+ /* TODO nick - review: font-size: 0px; */
+ display: none;
+}
+
+.rf-au-lst-dcrtn{
+ border-width: 1px;
+ border-style: solid;
+ border-color: '#{richSkin.panelBorderColor}';
+ padding: 0px;
+ background-color: '#{richSkin.tableBackgroundColor}';
+}
+
+.rf-au-lst-scrl{
+ overflow: auto;
+ overflow-x: hidden;
+ width: 200px;
+ max-height: 100px;
+ min-height: 20px;
+}
+
+.rf-au-opt{
+ padding: 2px;
+ white-space: nowrap;
+ cursor: default;
+ list-style-type: none;
+}
+
+.rf-au-sel{
+ padding: 1px;
+ width: 100%;
+ background-color: '#{richSkin.headerBackgroundColor}';
+ border-width: 1px;
+ border-style: dotted;
+ border-color: '#{richSkin.generalTextColor}';
+}
+
+.rf-au-shdw{
+ border: 0px solid red;
+ display: inline-block;
+ position: absolute;
+ float: left;
+ padding: 6px 6px 6px 6px;
+ top: -6px;
+ left: -7px;
+}
+
+.rf-au-shdw-t{
+ background-image: "url(#{resource['org.richfaces:combo_list_shadow.png']})";
+ background-position: top left;
+ position: absolute;
+ width: 6px;
+ top: 0px;
+ bottom: 6px;
+ left: 0px
+}
+
+.rf-au-shdw-l{
+ background-image: "url(#{resource['org.richfaces:combo_list_shadow.png']})";
+ background-position: bottom left;
+ position: absolute;
+ height: 6px;
+ bottom: 0px;
+ left: 0px;
+ right: 6px;
+}
+
+.rf-au-shdw-r{
+ background-image: "url(#{resource['org.richfaces:combo_list_shadow.png']})";
+ background-position: bottom right;
+ position: absolute;
+ width: 6px;
+ top: 6px;
+ bottom: 0px;
+ right: 0px;
+}
+
+.rf-au-shdw-b{
+ background-image: "url(#{resource['org.richfaces:combo_list_shadow.png']})";
+ background-position: right top;
+ position: absolute;
+ height: 6px;
+ top: 0px;
+ left: 6px;
+ right: 0px;
+}
+
+.rf-au-lst-ul{
+ margin: 0px;
+ padding: 0px;
+}
\ No newline at end of file
Modified: trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/select.js
===================================================================
--- trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/select.js 2010-10-15 16:14:23 UTC (rev 19581)
+++ trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/select.js 2010-10-15 16:45:47 UTC (rev 19582)
@@ -1,157 +1,131 @@
-//TODO: utils?
-(function (rf) {
- rf.KEYS = {
- BACKSPACE: 8,
- TAB: 9,
- RETURN: 13,
- ESC: 27,
- PAGEUP: 33,
- PAGEDOWN: 34,
- LEFT: 37,
- UP: 38,
- RIGHT: 39,
- DOWN: 40,
- DEL: 46
- };
-})(RichFaces);
-
(function ($, rf) {
rf.ui = rf.ui || {};
- var INTERFACE = {
- SelectListener : {
- processItem: function(e, element){}
- }
- };
-
- rf.ui.Select = function(id, listener, options) {
+ rf.ui.Select = function(id, options) {
this.id = id;
- this.select = $(document.getElementById(id));
- this.itemsCord = $(document.getElementById(options.itemsCord));
- this.selectItemCss = options.selectItemCss;
- this.itemCss = options.itemCss;
- this.selectListener = listener;
- this.select.bind("blur", $.proxy(this.__blurHandler, this));
- this.itemsCord.bind("mouseover", $.proxy(this.__mouseHandler, this));
- this.itemsCord.bind("click", $.proxy(this.__mouseHandler, this));
-
- this.index = -1;
- //TODO: from option map?
- this.visible = false;
- this.updateItemsList();
+ // TODO: move to defaultOptions ??
+ options['attachTo'] = id;
+ options['attachToBody'] = true;
+
+ this.selValueInput = $(document.getElementById(options.selValueInput));
+
+ this.input = $(document.getElementById(id+"Input"));
+ this.input.bind("click", $.proxy(this.__clickHandler, this));
+ this.input.bind("keydown", $.proxy(this.__keydownHandler, this));
+ this.input.bind("blur", $.proxy(this.__blurHandler, this));
+
+ this.items = options.items;
+
+ if(options.showControl) {
+ this.btn = $(document.getElementById(id+"Button"));
+ this.btn.bind("click", $.proxy(this.__clickHandler, this));
+ }
+ this.popupList = new rf.ui.SelectList(options.list, this, options);
};
rf.BaseComponent.extend(rf.ui.Select);
var $super = rf.ui.Select.$super;
$.extend(rf.ui.Select.prototype, ( function () {
-
- var processed = null;
-
- var isSelectListener = function(obj) {
- for (var method in INTERFACE.SelectListener) {
- if ( (typeof obj[method] != typeof INTERFACE.SelectListener[method]) ) {
- return false;
- }
- }
- return true;
- };
-
+
return{
name : "select",
+
+ __clickHandler: function(e) {
+ e.preventDefault();
+ if(!this.popupList.isVisible()) {
+ this.popupList.show();
+ } else {
+ this.popupList.hide();
+ }
+ this.__setInputFocus();
+ },
+
+ __keydownHandler: function(e) {
+ var code;
+
+ if(e.keyCode) {
+ code = e.keyCode;
+ } else if(e.which) {
+ code = e.which;
+ }
- show: function() {
- this.select.css("display", "");
- this.visible = true;
- },
-
- hide: function() {
- this.select.css("display", "none");
- this.visible = false;
+ if(this.popupList.isVisible()) {
+ switch(code) {
+ case rf.KEYS.DOWN:
+ e.preventDefault();
+ this.popupList.__selectNext();
+ this.__setInputFocus();
+ break;
+
+ case rf.KEYS.UP:
+ e.preventDefault();
+ this.popupList.__selectPrev();
+ this.__setInputFocus();
+ break;
+
+ case rf.KEYS.RETURN:
+ e.preventDefault();
+ this.popupList.__selectCurrent();
+ this.__setInputFocus();
+ return false;
+ break;
+ }
+ }
+ },
+
+ __setInputFocus: function() {
+ this.input.focus();
},
- processItem: function(e, element) {
- if(isSelectListener(this.selectListener)) {
- this.selectListener.processItem(e, element);
- }
+ __blurHandler: function(e) {
+ var target = $(e.originalEvent.explicitOriginalTarget);
+ if(!this.popupList.isPopupList(target)) {
+ this.popupList.hide();
+ return true;
+ }
+ return false;
},
-
- isVisible: function() {
- return this.visible;
- },
-
- __selectItem: function(e, index) {
- var item;
-
- if (this.index != -1) {
- item = this.items.eq(this.index);
- item.removeClass(this.selectItemCss);
- }
-
- this.index += index;
- if ( this.index < 0 ) {
- this.index = this.items.length - 1;
- } else if (this.index >= this.items.length) {
- this.index = 0;
- }
-
- item = this.items.eq(this.index);
- item.addClass(this.selectItemCss);
- },
-
- __onEnter: function(e) {
-
- },
-
- __onKeyUp: function(e) {
- this.__selectItem(e, -1);
- },
-
- __onKeyDown: function(e) {
- this.__selectItem(e, 1);
- },
-
- __getCurrentElement: function() {
- return processed;
- },
-
- __blurHandler: function(e) {
- processItem(e, processed);
- return false;
- },
-
- __mouseHandler: function(e) {
- var element = $(e.target).closest("."+this.itemCss, e.currentTarget);
- if (e && element) {
- if(e.type == 'mouseover') {
- if(processed) {
- processed.removeClass(this.selectItemCss);
- }
- element.addClass(this.selectItemCss);
- processed = element;
- }
-
- if(e.type == 'click') {
- this.processItem(e, element);
- }
- }
- return false;
- },
-
- updateItemsList: function () {
- this.items = this.itemsCord.find("."+this.itemCss);
- },
-
- __getItems: function () {
- return this.items;
- },
-
- __getId: function() {
- return this.id;
+
+ processItem: function(item) {
+ var key = $(item).attr("id");
+ var value = this.getItemValue(key);
+ this.saveItemValue(value);
+ var label = this.getItemLabel(key);
+ this.setValue(label);
+ this.popupList.hide();
+ this.__setInputFocus();
+ },
+
+ getItemValue: function(key) {
+ for(var i in this.items) {
+ var item = this.items[i];
+ if(item && item.id == key) {
+ return item.value;
+ }
+ }
+ },
+
+ getItemLabel: function(key) {
+ for(var i in this.items) {
+ var item = this.items[i];
+ if(item && item.id == key) {
+ return item.label;
+ }
+ }
+ },
+
+ saveItemValue: function(value) {
+ this.selValueInput.val(value);
+ },
+
+ setValue: function(value){
+ this.input.val(value);
}
}
+
})());
})(jQuery, window.RichFaces);
Modified: trunk/ui/input/ui/src/main/templates/inplaceInput.template.xml
===================================================================
--- trunk/ui/input/ui/src/main/templates/inplaceInput.template.xml 2010-10-15 16:14:23 UTC (rev 19581)
+++ trunk/ui/input/ui/src/main/templates/inplaceInput.template.xml 2010-10-15 16:45:47 UTC (rev 19582)
@@ -30,7 +30,7 @@
<cc:interface>
<cdk:class>org.richfaces.renderkit.html.InplaceInputRenderer
</cdk:class>
- <cdk:superclass>org.richfaces.renderkit.InplaceInputBaseRenderer
+ <cdk:superclass>org.richfaces.renderkit.InplaceInputRendererBase
</cdk:superclass>
<cdk:component-family>org.richfaces.InplaceInput
</cdk:component-family>
Modified: trunk/ui/input/ui/src/main/templates/inplaceSelect.template.xml
===================================================================
--- trunk/ui/input/ui/src/main/templates/inplaceSelect.template.xml 2010-10-15 16:14:23 UTC (rev 19581)
+++ trunk/ui/input/ui/src/main/templates/inplaceSelect.template.xml 2010-10-15 16:45:47 UTC (rev 19582)
@@ -20,7 +20,7 @@
<cc:interface>
<cdk:class>org.richfaces.renderkit.html.InplaceSelectRenderer
</cdk:class>
- <cdk:superclass>org.richfaces.renderkit.InplaceSelectBaseRenderer
+ <cdk:superclass>org.richfaces.renderkit.InplaceSelectRendererBase
</cdk:superclass>
<cdk:component-family>org.richfaces.InplaceSelect
</cdk:component-family>
@@ -88,7 +88,7 @@
<span class="rf-is-shdw-b"></span>
<span class="rf-is-lst-dec">
<span class="rf-is-lst-scrl" id="#{clientId}Items" style="height: #{component.attributes['listHeight']}">
- <cdk:call expression="encodeOptions(facesContext, component, clientSelectItems);"/>
+ <cdk:call expression="encodeItems(facesContext, component, clientSelectItems);"/>
</span>
</span>
</span>
Added: trunk/ui/input/ui/src/main/templates/select.template.xml
===================================================================
--- trunk/ui/input/ui/src/main/templates/select.template.xml (rev 0)
+++ trunk/ui/input/ui/src/main/templates/select.template.xml 2010-10-15 16:45:47 UTC (rev 19582)
@@ -0,0 +1,68 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<cdk:root xmlns="http://jboss.org/schema/richfaces/cdk/xhtml-el" xmlns:cdk="http://jboss.org/schema/richfaces/cdk/core"
+ xmlns:c="http://jboss.org/schema/richfaces/cdk/jstl/core" xmlns:cc="http://jboss.org/schema/richfaces/cdk/jsf/composite"
+ xmlns:javaee="http://java.sun.com/xml/ns/javaee">
+
+ <cc:interface>
+ <cdk:class>org.richfaces.renderkit.html.SelectRenderer</cdk:class>
+ <cdk:superclass>org.richfaces.renderkit.SelectRendererBase</cdk:superclass>
+ <cdk:component-family>org.richfaces.Select</cdk:component-family>
+ <cdk:renderer-type>org.richfaces.SelectRenderer</cdk:renderer-type>
+ <cdk:renders-children>true</cdk:renders-children>
+ </cc:interface>
+
+ <cc:implementation>
+
+ <cdk:object type="java.util.List" type-arguments="org.richfaces.renderkit.ClientSelectItem" name="clientSelectItems"
+ value="#{getConvertedSelectItems(facesContext, component)}" />
+
+ <cdk:object type="java.lang.Object" name="disabled" value="#{component.attributes['disabled']}" />
+
+ <div id="#{clientId}" class="rf-au-fld">
+ <div style="position : relative; overflow : hidden; text-align : left; padding-right : 21px;">
+ <input id="#{clientId}selValue" name="#{clientId}" type="hidden" value="#{getValue(facesContext, component)}"/>
+ <input cdk:passThroughWithExclusions="class autocomplete id value disabled name type readonly"
+ id="#{clientId}Input"
+ value="#{getSelectInputLabel(facesContext, component)}"
+ disabled="#{disabled}"
+ type="text"
+ class="rf-au-fnt rf-au-inp"
+ autocomplete="off"
+ readonly="readonly"/>
+
+ <c:if test="#{component.attributes['showButton']}">
+ <c:if test="#{component.attributes['disabled']}">
+ <div id="#{clientId}Button" class="rf-au-btn">
+ <div class="rf-au-btn-arrow"></div>
+ </div>
+ </c:if>
+ <c:if test="#{!component.attributes['disabled']}">
+ <div id="#{clientId}Button" class="rf-au-btn">
+ <div class="rf-au-btn-arrow"></div>
+ </div>
+ </c:if>
+ </c:if>
+ </div>
+
+ <div id="#{clientId}List" class="rf-au-lst-cord">
+ <cdk:call expression="renderListHandlers(facesContext, component);"/>
+ <div class="rf-au-shdw">
+ <div class="rf-au-shdw-t"></div>
+ <div class="rf-au-shdw-l"></div>
+ <div class="rf-au-shdw-r"></div>
+ <div class="rf-au-shdw-b"></div>
+
+ <div class="rf-au-lst-dcrtn">
+ <div class="rf-au-lst-scrl">
+ <cdk:call expression="encodeItems(facesContext, component, clientSelectItems);"/>
+ </div>
+ </div>
+ </div>
+ </div>
+ <script type="text/javascript">
+ <cdk:call expression="buildScript(responseWriter, facesContext, component, clientSelectItems);"/>
+ </script>
+ </div>
+ </cc:implementation>
+</cdk:root>
13 years, 8 months
JBoss Rich Faces SVN: r19581 - sandbox/trunk/prototypes/calendar.
by richfaces-svn-commits@lists.jboss.org
Author: pyaschenko
Date: 2010-10-15 12:14:23 -0400 (Fri, 15 Oct 2010)
New Revision: 19581
Modified:
sandbox/trunk/prototypes/calendar/calendar.js
Log:
https://jira.jboss.org/browse/RF-9152
https://jira.jboss.org/browse/RF-9168
small fix
Modified: sandbox/trunk/prototypes/calendar/calendar.js
===================================================================
--- sandbox/trunk/prototypes/calendar/calendar.js 2010-10-15 16:03:22 UTC (rev 19580)
+++ sandbox/trunk/prototypes/calendar/calendar.js 2010-10-15 16:14:23 UTC (rev 19581)
@@ -1676,7 +1676,7 @@
offset = offset || {left:0,top:0};
var width = jqe.outerWidth()+"px", height = jqe.outerHeight()+"px";
var pos = jqe.position();
- var left = Math.round(pos.left)+offset.left+"px", top = Math.round(pos.top)+offset.top+"px";
+ var left = Math.floor(pos.left)+offset.left+"px", top = Math.floor(pos.top)+offset.top+"px";
var element;
for (var i = 0; i<elements.length;i++) {
element = elements[i];
13 years, 8 months
JBoss Rich Faces SVN: r19580 - sandbox/trunk/prototypes/calendar.
by richfaces-svn-commits@lists.jboss.org
Author: pyaschenko
Date: 2010-10-15 12:03:22 -0400 (Fri, 15 Oct 2010)
New Revision: 19580
Modified:
sandbox/trunk/prototypes/calendar/calendar-utils.js
Log:
https://jira.jboss.org/browse/RF-9487
Modified: sandbox/trunk/prototypes/calendar/calendar-utils.js
===================================================================
--- sandbox/trunk/prototypes/calendar/calendar-utils.js 2010-10-15 11:04:48 UTC (rev 19579)
+++ sandbox/trunk/prototypes/calendar/calendar-utils.js 2010-10-15 16:03:22 UTC (rev 19580)
@@ -144,9 +144,26 @@
var match = dateString.match(re);
if (match!=null)
{
- var yy = parseInt(match[y],10); if (isNaN(yy)) return null; else if (yy<70) yy+=2000; else if (yy<100) yy+=1900;
+ // set default century start
+ var correctYear = false;
+ var defaultCenturyStart = new Date();
+ defaultCenturyStart.setFullYear(defaultCenturyStart.getFullYear()-80);
+
+ var yy = parseInt(match[y],10);
+ if (isNaN(yy)) return null;
+ else if (yy<100){
+ // calculate full year if year has only two digits
+ var defaultCenturyStartYear = defaultCenturyStart.getFullYear();
+ var ambiguousTwoDigitYear = defaultCenturyStartYear % 100;
+ correctYear = yy == ambiguousTwoDigitYear;
+ yy += Math.floor(defaultCenturyStartYear/100)*100 + (yy < ambiguousTwoDigitYear ? 100 : 0);
+ }
+
var mm = parseInt(match[m],10); if (isNaN(mm)) mm = Richfaces.Calendar.getMonthByLabel(match[m], shortLabel ? monthNamesShort : monthNames); else if (--mm<0 || mm>11) return null;
- var dd = parseInt(match[d],10); if (isNaN(dd) || dd<1 || dd>this.daysInMonth(yy, mm)) return null;
+ var addDay = correctYear ? 1 : 0;
+ var dd = parseInt(match[d],10); if (isNaN(dd) || dd<1 || dd>this.daysInMonth(yy, mm) + addDay) return null;
+
+ var date = new Date(yy, mm, dd);
// time parsing
if (min!=undefined && h!=undefined)
@@ -166,11 +183,18 @@
} else if (hh==12) hh = 0;
}
else if (hh<0 || hh>23) return null;
-
- return new Date(yy, mm, dd, hh, mmin, 0);
+
+ date.setHours(hh); date.setMinutes(mmin);
}
- return new Date(yy, mm, dd);
+ if (correctYear) {
+ if (date.getTime() < defaultCenturyStart.getTime()) {
+ date.setFullYear(yy + 100);
+ }
+ if (date.getMonth() != mm) return null;
+ }
+
+ return date;
}
return null;
},
13 years, 8 months
JBoss Rich Faces SVN: r19579 - modules/tests/metamer/trunk/application/src/main/webapp/resources/css.
by richfaces-svn-commits@lists.jboss.org
Author: ppitonak(a)redhat.com
Date: 2010-10-15 07:04:48 -0400 (Fri, 15 Oct 2010)
New Revision: 19579
Modified:
modules/tests/metamer/trunk/application/src/main/webapp/resources/css/common.ecss
Log:
* fixed problem with header rendering wrong in Firefox
Modified: modules/tests/metamer/trunk/application/src/main/webapp/resources/css/common.ecss
===================================================================
--- modules/tests/metamer/trunk/application/src/main/webapp/resources/css/common.ecss 2010-10-15 10:35:57 UTC (rev 19578)
+++ modules/tests/metamer/trunk/application/src/main/webapp/resources/css/common.ecss 2010-10-15 11:04:48 UTC (rev 19579)
@@ -10,7 +10,7 @@
.header .external-table {
border-width: 0px;
border-collapse: collapse;
- padding-bottom: 30px;
+ border-style: dotted;
}
.header-column {
13 years, 8 months
JBoss Rich Faces SVN: r19578 - in modules/tests/metamer/trunk/application/src/main: webapp/components and 1 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: ppitonak(a)redhat.com
Date: 2010-10-15 06:35:57 -0400 (Fri, 15 Oct 2010)
New Revision: 19578
Added:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/RichTabBean.java
modules/tests/metamer/trunk/application/src/main/webapp/components/richTab/
modules/tests/metamer/trunk/application/src/main/webapp/components/richTab/list.xhtml
modules/tests/metamer/trunk/application/src/main/webapp/components/richTab/simple.xhtml
Modified:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/RichBean.java
Log:
https://jira.jboss.org/browse/RFPL-875
* one page for rich:tab added
Modified: modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/RichBean.java
===================================================================
--- modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/RichBean.java 2010-10-15 00:28:55 UTC (rev 19577)
+++ modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/RichBean.java 2010-10-15 10:35:57 UTC (rev 19578)
@@ -132,6 +132,7 @@
components.put("richProgressBar", "Rich Progress Bar");
components.put("richSubTable", "Rich Subtable");
components.put("richSubTableToggleControl", "Rich Subtable Toggle Control");
+ components.put("richTab", "Rich Tab");
components.put("richTabPanel", "Rich Tab Panel");
components.put("richToggleControl", "Rich Toggle Control");
components.put("richTogglePanel", "Rich Toggle Panel");
Added: modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/RichTabBean.java
===================================================================
--- modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/RichTabBean.java (rev 0)
+++ modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/RichTabBean.java 2010-10-15 10:35:57 UTC (rev 19578)
@@ -0,0 +1,71 @@
+/*******************************************************************************
+ * 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.tests.metamer.bean;
+
+import java.io.Serializable;
+
+import javax.annotation.PostConstruct;
+import javax.faces.bean.ManagedBean;
+import javax.faces.bean.SessionScoped;
+import org.richfaces.component.html.HtmlTab;
+
+import org.richfaces.tests.metamer.Attributes;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Managed bean for rich:tab.
+ *
+ * @author <a href="mailto:ppitonak@redhat.com">Pavol Pitonak</a>
+ * @version $Revision$
+ */
+@ManagedBean(name = "richTabBean")
+@SessionScoped
+public class RichTabBean implements Serializable {
+
+ private static final long serialVersionUID = -1L;
+ private static Logger logger;
+ private Attributes attributes;
+
+ /**
+ * Initializes the managed bean.
+ */
+ @PostConstruct
+ public void init() {
+ logger = LoggerFactory.getLogger(getClass());
+ logger.debug("initializing bean " + getClass().getName());
+
+ attributes = Attributes.getUIComponentAttributes(HtmlTab.class, getClass());
+
+ attributes.setAttribute("header", "tab1 header");
+ attributes.setAttribute("name", "tab1");
+ attributes.setAttribute("rendered", true);
+ }
+
+ public Attributes getAttributes() {
+ return attributes;
+ }
+
+ public void setAttributes(Attributes attributes) {
+ this.attributes = attributes;
+ }
+}
Property changes on: modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/RichTabBean.java
___________________________________________________________________
Name: svn:keywords
+ Revision
Added: modules/tests/metamer/trunk/application/src/main/webapp/components/richTab/list.xhtml
===================================================================
--- modules/tests/metamer/trunk/application/src/main/webapp/components/richTab/list.xhtml (rev 0)
+++ modules/tests/metamer/trunk/application/src/main/webapp/components/richTab/list.xhtml 2010-10-15 10:35:57 UTC (rev 19578)
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!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:ui="http://java.sun.com/jsf/facelets"
+ xmlns:metamer="http://java.sun.com/jsf/composite/metamer">
+
+ <!--
+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.
+ -->
+
+ <ui:composition template="/templates/list.xhtml">
+
+ <ui:define name="pageTitle">Rich Tab</ui:define>
+
+ <ui:define name="links">
+
+ <metamer:testPageLink id="simple" outcome="simple" value="Simple">
+ Simple page containing rich:tabPanel with several <b>rich:tab</b>s and input boxes for all its attributes.
+ </metamer:testPageLink>
+
+ </ui:define>
+
+ </ui:composition>
+
+</html>
Added: modules/tests/metamer/trunk/application/src/main/webapp/components/richTab/simple.xhtml
===================================================================
--- modules/tests/metamer/trunk/application/src/main/webapp/components/richTab/simple.xhtml (rev 0)
+++ modules/tests/metamer/trunk/application/src/main/webapp/components/richTab/simple.xhtml 2010-10-15 10:35:57 UTC (rev 19578)
@@ -0,0 +1,105 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!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:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"
+ xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:metamer="http://java.sun.com/jsf/composite/metamer"
+ xmlns:rich="http://richfaces.org/rich" xmlns:a4j="http://richfaces.org/a4j">
+
+ <!--
+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.
+ -->
+
+ <ui:composition template="/templates/template.xhtml">
+ <ui:define name="head">
+ <f:metadata>
+ <f:viewParam name="templates" value="#{templateBean.templates}">
+ <f:converter converterId="templatesListConverter" />
+ </f:viewParam>
+ </f:metadata>
+ </ui:define>
+
+ <ui:define name="outOfTemplateBefore">
+ </ui:define>
+
+ <ui:define name="component">
+
+ <rich:tabPanel id="tabPanel">
+ <rich:tab id="tab1"
+ active="#{richTabBean.attributes['active'].value}"
+ contentClass="#{richTabBean.attributes['contentClass'].value}"
+ converter="#{richTabBean.attributes['converter'].value}"
+ dir="#{richTabBean.attributes['dir'].value}"
+ disabled="#{richTabBean.attributes['disabled'].value}"
+ header="#{richTabBean.attributes['header'].value}"
+ headerClass="#{richTabBean.attributes['headerClass'].value}"
+ headerClassActive="#{richTabBean.attributes['headerClassActive'].value}"
+ headerClassDisabled="#{richTabBean.attributes['headerClassDisabled'].value}"
+ headerClassInactive="#{richTabBean.attributes['headerClassInactive'].value}"
+ headerStyle="#{richTabBean.attributes['headerStyle'].value}"
+ lang="#{richTabBean.attributes['lang'].value}"
+ localValue="#{richTabBean.attributes['localValue'].value}"
+ name="#{richTabBean.attributes['name'].value}"
+ onclick="#{richTabBean.attributes['onclick'].value}"
+ ondblclick="#{richTabBean.attributes['ondblclick'].value}"
+ onenter="#{richTabBean.attributes['onenter'].value}"
+ onheaderclick="#{richTabBean.attributes['onheaderclick'].value}"
+ onheaderdblclick="#{richTabBean.attributes['onheaderdblclick'].value}"
+ onheadermousedown="#{richTabBean.attributes['onheadermousedown'].value}"
+ onheadermousemove="#{richTabBean.attributes['onheadermousemove'].value}"
+ onheadermouseup="#{richTabBean.attributes['onheadermouseup'].value}"
+ onleave="#{richTabBean.attributes['onleave'].value}"
+ onmousedown="#{richTabBean.attributes['onmousedown'].value}"
+ onmousemove="#{richTabBean.attributes['onmousemove'].value}"
+ onmouseout="#{richTabBean.attributes['onmouseout'].value}"
+ onmouseover="#{richTabBean.attributes['onmouseover'].value}"
+ onmouseup="#{richTabBean.attributes['onmouseup'].value}"
+ rendered="#{richTabBean.attributes['rendered'].value}"
+ style="#{richTabBean.attributes['style'].value}"
+ styleClass="#{richTabBean.attributes['styleClass'].value}"
+ switchType="#{richTabBean.attributes['switchType'].value}"
+ tabPanel="#{richTabBean.attributes['tabPanel'].value}"
+ title="#{richTabBean.attributes['title'].value}"
+ value="#{richTabBean.attributes['value'].value}"
+ >
+ content of tab 1
+ </rich:tab>
+ <rich:tab id="tab2" name="tab2" header="tab2 header">
+ content of tab 2
+ </rich:tab>
+ <rich:tab id="tab3" name="tab3" header="tab3 header">
+ content of tab 3
+ </rich:tab>
+ <rich:tab id="tab4" name="tab4" header="tab4 header" disabled="true">
+ content of tab 4
+ </rich:tab>
+ <rich:tab id="tab5" name="tab5" header="tab5 header">
+ content of tab 5
+ </rich:tab>
+ </rich:tabPanel>
+
+ </ui:define>
+
+ <ui:define name="outOfTemplateAfter">
+ Attributes for the first tab:
+ <metamer:attributes value="#{richTabBean.attributes}" id="attributes" render="log"/>
+ </ui:define>
+
+ </ui:composition>
+</html>
\ No newline at end of file
13 years, 8 months
JBoss Rich Faces SVN: r19577 - in branches/RF-7817: core/impl and 12 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: nbelaevski
Date: 2010-10-14 20:28:55 -0400 (Thu, 14 Oct 2010)
New Revision: 19577
Added:
branches/RF-7817/core/impl/src/main/java/org/richfaces/application/push/
branches/RF-7817/core/impl/src/main/java/org/richfaces/application/push/impl/
branches/RF-7817/core/impl/src/main/java/org/richfaces/application/push/impl/TopicImpl.java
branches/RF-7817/core/impl/src/main/java/org/richfaces/application/push/impl/TopicsContextImpl.java
branches/RF-7817/push-redesign-app/src/main/java/demo/HornetQInitializer.java
branches/RF-7817/push-redesign-app/src/main/java/demo/TopicsInitializer.java
branches/RF-7817/push-redesign/checkstyle-suppressions.xml
branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/push/impl/AbstractSession.java
branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/push/impl/DefaultMessageDataSerializer.java
branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/push/impl/SessionManagerImpl.java
branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/push/impl/jms/
branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/push/impl/jms/MessagingContext.java
branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/push/impl/jms/PublisherContextImpl.java
branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/push/impl/jms/PushHandlerImpl.java
branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/push/impl/jms/SessionImpl.java
Removed:
branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/push/impl/DefaultMessageSerializer.java
branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/push/impl/MessagesContextImpl.java
branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/push/impl/PushRequestWorker.java
branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/push/impl/PushSessionImpl.java
branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/push/impl/PushSessionTrackerImpl.java
Modified:
branches/RF-7817/core/impl/checkstyle-suppressions.xml
branches/RF-7817/core/impl/src/main/java/org/richfaces/application/DefaultModule.java
branches/RF-7817/pom.xml
branches/RF-7817/push-redesign-app/pom.xml
branches/RF-7817/push-redesign-app/src/main/webapp/WEB-INF/faces-config.xml
branches/RF-7817/push-redesign-app/src/main/webapp/WEB-INF/web.xml
branches/RF-7817/push-redesign/pom.xml
branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/push/impl/AtmospherePushHandler.java
branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/push/impl/RequestImpl.java
branches/RF-7817/push-redesign/src/main/java/org/richfaces/webapp/PushServlet.java
branches/RF-7817/ui/common/ui/checkstyle-suppressions.xml
branches/RF-7817/ui/output/ui/checkstyle-suppressions.xml
Log:
https://jira.jboss.org/browse/RF-7817
- JMS migration
Modified: branches/RF-7817/core/impl/checkstyle-suppressions.xml
===================================================================
--- branches/RF-7817/core/impl/checkstyle-suppressions.xml 2010-10-15 00:26:15 UTC (rev 19576)
+++ branches/RF-7817/core/impl/checkstyle-suppressions.xml 2010-10-15 00:28:55 UTC (rev 19577)
@@ -33,4 +33,8 @@
<!-- TODO it is hot fix for building process, this files belong to the ui/output/trunk/panela/ui module,
and must be removed from here -->
<suppress checks="IllegalCatch" files="AbstractTogglePanel.java" />
+
+ <!-- TODO it is hot fix for building process, this files belong to the push-redesign module,
+ and must be removed from here -->
+ <suppress checks="IllegalCatch" files="RequestImpl.java" />
</suppressions>
Modified: branches/RF-7817/core/impl/src/main/java/org/richfaces/application/DefaultModule.java
===================================================================
--- branches/RF-7817/core/impl/src/main/java/org/richfaces/application/DefaultModule.java 2010-10-15 00:26:15 UTC (rev 19576)
+++ branches/RF-7817/core/impl/src/main/java/org/richfaces/application/DefaultModule.java 2010-10-15 00:28:55 UTC (rev 19577)
@@ -2,6 +2,8 @@
import org.richfaces.application.configuration.ConfigurationService;
import org.richfaces.application.configuration.ConfigurationServiceImpl;
+import org.richfaces.application.push.TopicsContext;
+import org.richfaces.application.push.impl.TopicsContextImpl;
import org.richfaces.cache.Cache;
import org.richfaces.l10n.BundleLoader;
import org.richfaces.renderkit.AjaxDataSerializer;
@@ -25,6 +27,7 @@
factory.setInstance(DependencyInjector.class, new DependencyInjectionServiceImpl());
factory.setInstance(MessageFactory.class, new MessageFactoryImpl(new BundleLoader()));
factory.setInstance(ResourceLibraryFactory.class, new ResourceLibraryFactoryImpl());
+ factory.setInstance(TopicsContext.class, new TopicsContextImpl());
}
}
Added: branches/RF-7817/core/impl/src/main/java/org/richfaces/application/push/impl/TopicImpl.java
===================================================================
--- branches/RF-7817/core/impl/src/main/java/org/richfaces/application/push/impl/TopicImpl.java (rev 0)
+++ branches/RF-7817/core/impl/src/main/java/org/richfaces/application/push/impl/TopicImpl.java 2010-10-15 00:28:55 UTC (rev 19577)
@@ -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.application.push.impl;
+
+import org.richfaces.application.push.MessageDataSerializer;
+import org.richfaces.application.push.Topic;
+import org.richfaces.application.push.TopicKey;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class TopicImpl implements Topic {
+
+ private TopicKey key;
+
+ private volatile MessageDataSerializer serializer;
+
+ public TopicImpl(TopicKey key) {
+ super();
+ this.key = key;
+ }
+
+ public MessageDataSerializer getMessageSerializer() {
+ return serializer;
+ }
+
+ public void setMessageSerializer(MessageDataSerializer serializer) {
+ this.serializer = serializer;
+ }
+
+ public TopicKey getKey() {
+ return key;
+ }
+
+}
Added: branches/RF-7817/core/impl/src/main/java/org/richfaces/application/push/impl/TopicsContextImpl.java
===================================================================
--- branches/RF-7817/core/impl/src/main/java/org/richfaces/application/push/impl/TopicsContextImpl.java (rev 0)
+++ branches/RF-7817/core/impl/src/main/java/org/richfaces/application/push/impl/TopicsContextImpl.java 2010-10-15 00:28:55 UTC (rev 19577)
@@ -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.application.push.impl;
+
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
+import org.richfaces.application.push.Topic;
+import org.richfaces.application.push.TopicKey;
+import org.richfaces.application.push.TopicsContext;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class TopicsContextImpl implements TopicsContext {
+
+ private ConcurrentMap<TopicKey, Topic> topics = new ConcurrentHashMap<TopicKey, Topic>();
+
+ public Topic getOrCreateTopic(TopicKey key) {
+ Topic result = topics.get(key);
+
+ if (result == null) {
+ Topic newTopic = new TopicImpl(key);
+ result = topics.putIfAbsent(key, newTopic);
+ if (result == null) {
+ result = newTopic;
+ }
+ }
+
+ return result;
+ }
+
+ public Topic getTopic(TopicKey key) {
+ return topics.get(key);
+ }
+
+ public void removeTopic(TopicKey key) {
+ topics.remove(key);
+ }
+
+}
Modified: branches/RF-7817/pom.xml
===================================================================
--- branches/RF-7817/pom.xml 2010-10-15 00:26:15 UTC (rev 19576)
+++ branches/RF-7817/pom.xml 2010-10-15 00:28:55 UTC (rev 19577)
@@ -29,6 +29,8 @@
<module>archetypes</module>
<module>examples</module>
<!--<module>docs</module>-->
+ <module>push-redesign</module>
+ <module>push-redesign-app</module>
</modules>
<build>
Added: branches/RF-7817/push-redesign/checkstyle-suppressions.xml
===================================================================
--- branches/RF-7817/push-redesign/checkstyle-suppressions.xml (rev 0)
+++ branches/RF-7817/push-redesign/checkstyle-suppressions.xml 2010-10-15 00:28:55 UTC (rev 19577)
@@ -0,0 +1,40 @@
+<?xml version="1.0"?>
+
+<!DOCTYPE suppressions PUBLIC
+ "-//Puppy Crawl//DTD Suppressions 1.0//EN"
+ "http://www.puppycrawl.com/dtds/suppressions_1_0.dtd">
+
+<!-- NOTE: Because of issues with maven checkstyle plugin each suppression
+ file must have all suppressions defined.
+
+ See RF-9077 for details. -->
+<suppressions>
+ <suppress checks="DoubleCheckedLocking" files="MultipartRequestRegistry.java" />
+ <suppress checks="FallThrough" files="JSMin.java" />
+ <suppress checks="IllegalCatch" files="UISwitchablePanel.java" />
+ <suppress checks="ModifiedControlVariable" files="MultipartRequest.java" />
+ <suppress checks="IllegalCatch" files="StagingServer.java" />
+ <suppress checks="IllegalCatch" files="PartialViewContextImpl.java" />
+ <suppress checks="FallThrough" files="StagingServer.java" />
+ <suppress checks="ModifiedControlVariable" files="Cookie.java" />
+ <suppress checks="IllegalCatch" files="CacheManager.java" />
+ <suppress checks="MissingSwitchDefault" files="JSONTokener.java" />
+ <suppress checks="IllegalCatch" files="AjaxViewRoot.java" />
+ <suppress checks="FallThrough" files="XMLTokener.java" />
+ <suppress checks="IllegalCatch" files="ResourceHandlerImpl.java" />
+ <suppress checks="IllegalThrows" files="AbstractThreadedTest.java" />
+ <suppress checks="ModifiedControlVariable" files="URLCodec.java" />
+
+ <!-- TODO it is hot fix for building process, this files belong to the test-base module,
+ and must be removed from here -->
+ <suppress checks="IllegalCatch" files="AbstractThreadedTest.java" />
+ <suppress checks="IllegalCatch" files="StagingServer.java" />
+
+ <!-- TODO it is hot fix for building process, this files belong to the ui/output/trunk/panela/ui module,
+ and must be removed from here -->
+ <suppress checks="IllegalCatch" files="AbstractTogglePanel.java" />
+
+ <!-- TODO it is hot fix for building process, this files belong to the push-redesign module,
+ and must be removed from here -->
+ <suppress checks="IllegalCatch" files="RequestImpl.java" />
+</suppressions>
Modified: branches/RF-7817/push-redesign/pom.xml
===================================================================
--- branches/RF-7817/push-redesign/pom.xml 2010-10-15 00:26:15 UTC (rev 19576)
+++ branches/RF-7817/push-redesign/pom.xml 2010-10-15 00:28:55 UTC (rev 19577)
@@ -21,6 +21,13 @@
<build>
<plugins>
<plugin>
+ <!-- Checkstyle only required here because suppressions needed -->
+ <artifactId>maven-checkstyle-plugin</artifactId>
+ <configuration>
+ <suppressionsLocation>checkstyle-suppressions.xml</suppressionsLocation>
+ </configuration>
+ </plugin>
+ <plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
@@ -68,5 +75,11 @@
<artifactId>atmosphere-runtime</artifactId>
<version>0.6.2</version>
</dependency>
+ <dependency>
+ <groupId>javax.jms</groupId>
+ <artifactId>jms</artifactId>
+ <version>1.1</version>
+ <optional>true</optional>
+ </dependency>
</dependencies>
</project>
Added: branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/push/impl/AbstractSession.java
===================================================================
--- branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/push/impl/AbstractSession.java (rev 0)
+++ branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/push/impl/AbstractSession.java 2010-10-15 00:28:55 UTC (rev 19577)
@@ -0,0 +1,152 @@
+/*
+ * 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.application.push.impl;
+
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import org.richfaces.application.push.Request;
+import org.richfaces.application.push.Session;
+import org.richfaces.application.push.SessionListener;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public abstract class AbstractSession implements Session {
+
+ private static final int MAX_INACTIVE_INTERVAL = 60 * 1000;
+
+ private static final SessionListener[] EMPTY_SESSION_LISTENERS_ARRAY = new SessionListener[0];
+
+ private static enum Events {
+ connected {
+ @Override
+ public void notifyListener(AbstractSession session, SessionListener listener) {
+ listener.onRequestConnected(session);
+ }
+ },
+
+ disconnected {
+ @Override
+ public void notifyListener(AbstractSession session, SessionListener listener) {
+ listener.onRequestDisconnected(session);
+ }
+ },
+
+ destroyed {
+ @Override
+ public void notifyListener(AbstractSession session, SessionListener listener) {
+ listener.onSessionDestroyed(session);
+ }
+ };
+
+ abstract void notifyListener(AbstractSession session, SessionListener listener);
+
+ public void notifyListeners(AbstractSession session) {
+ for (SessionListener listener : session.listeners) {
+ notifyListener(session, listener);
+ }
+ }
+ }
+
+ private final String id;
+
+ private volatile long lastAccessedTime;
+
+ private volatile Request request;
+
+ //TODO performance?
+ private List<SessionListener> listeners = new CopyOnWriteArrayList<SessionListener>();
+
+ public AbstractSession(String id) {
+ super();
+ this.id = id;
+
+ resetLastAccessedTimeToCurrent();
+ }
+
+ private void resetLastAccessedTimeToCurrent() {
+ lastAccessedTime = System.currentTimeMillis();
+ }
+
+ public void connect(Request request) throws Exception {
+ if (this.request != null) {
+ throw new IllegalStateException("already connected");
+ }
+
+ this.request = request;
+
+ Events.connected.notifyListeners(this);
+
+ request.suspend();
+ }
+
+ public void disconnect(Request request) throws Exception {
+ this.request = null;
+ resetLastAccessedTimeToCurrent();
+
+ Events.disconnected.notifyListeners(this);
+ }
+
+ public long getLastAccessedTime() {
+ if (request != null) {
+ return System.currentTimeMillis();
+ }
+
+ return lastAccessedTime;
+ }
+
+ public int getMaxInactiveInterval() {
+ return MAX_INACTIVE_INTERVAL;
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public void addSessionListener(SessionListener sessionListener) {
+ listeners.add(sessionListener);
+ }
+
+ public SessionListener[] getSessionListeners() {
+ return listeners.toArray(EMPTY_SESSION_LISTENERS_ARRAY);
+ }
+
+ public void removeSessionListener(SessionListener sessionListener) {
+ listeners.remove(sessionListener);
+ }
+
+ public Request getRequest() {
+ return request;
+ }
+
+ public void destroy() {
+ if (request != null) {
+ //TODO - clean up request
+ }
+
+ Events.destroyed.notifyListeners(this);
+ // TODO Auto-generated method stub
+
+ }
+}
Modified: branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/push/impl/AtmospherePushHandler.java
===================================================================
--- branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/push/impl/AtmospherePushHandler.java 2010-10-15 00:26:15 UTC (rev 19576)
+++ branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/push/impl/AtmospherePushHandler.java 2010-10-15 00:28:55 UTC (rev 19577)
@@ -22,44 +22,59 @@
package org.richfaces.application.push.impl;
import java.io.IOException;
+import java.util.UUID;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.atomic.AtomicInteger;
+import javax.servlet.ServletConfig;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.atmosphere.cpr.AtmosphereHandler;
import org.atmosphere.cpr.AtmosphereResource;
import org.atmosphere.cpr.AtmosphereResourceEvent;
-import org.richfaces.application.push.PushSession;
-import org.richfaces.application.push.PushSessionTracker;
-import org.richfaces.application.push.SubscriptionContext;
+import org.richfaces.application.push.Request;
+import org.richfaces.application.push.Session;
+import org.richfaces.application.push.SessionManager;
import org.richfaces.application.push.TopicKey;
/**
* @author Nick Belaevski
*
*/
-public class AtmospherePushHandler implements AtmosphereHandler<HttpServletRequest, HttpServletResponse> {
+public abstract class AtmospherePushHandler implements AtmosphereHandler<HttpServletRequest, HttpServletResponse> {
+ private static final ThreadFactory DAEMON_THREADS_FACTORY = new ThreadFactory() {
+
+ private final AtomicInteger threadsCounter = new AtomicInteger();
+
+ public Thread newThread(Runnable r) {
+ Thread t = new Thread(r, "rf-push-worker-thread-" + threadsCounter.getAndIncrement());
+ t.setDaemon(true);
+
+ return t;
+ }
+ };
+
private static final String PUSH_SESSION_ID_PARAM = "pushSessionId";
- private PushSessionTracker pushTracker;
+ private SessionManager sessionManager;
- private PushRequestWorker worker;
+ private ExecutorService worker;
- public AtmospherePushHandler(SubscriptionContext subscriptionContext) {
+ public AtmospherePushHandler() {
super();
- pushTracker = new PushSessionTrackerImpl(subscriptionContext);
- worker = new PushRequestWorker(8);
+ sessionManager = new SessionManagerImpl(DAEMON_THREADS_FACTORY);
+ worker = Executors.newCachedThreadPool(DAEMON_THREADS_FACTORY);
}
- protected PushSessionTracker getPushTracker() {
- return pushTracker;
+ protected SessionManager getSessionManager() {
+ return sessionManager;
}
- /* (non-Javadoc)
- * @see org.atmosphere.cpr.AtmosphereHandler#onRequest(org.atmosphere.cpr.AtmosphereResource)
- */
public void onRequest(AtmosphereResource<HttpServletRequest, HttpServletResponse> resource) throws IOException {
// TODO Auto-generated method stub
@@ -68,13 +83,13 @@
String pushSessionId = req.getParameter(PUSH_SESSION_ID_PARAM);
- PushSession pushSession = null;
+ Session session = null;
if (pushSessionId != null) {
- pushSession = getPushTracker().getPushSession(pushSessionId);
+ session = getSessionManager().getPushSession(pushSessionId);
}
- if (pushSession == null) {
+ if (session == null) {
//TODO - debug log
resp.sendError(HttpServletResponse.SC_BAD_REQUEST);
return;
@@ -82,7 +97,12 @@
resp.setContentType("text/plain");
- pushSession.connect(new RequestImpl(resource, pushSession, worker));
+ try {
+ session.connect(createRequest(resource, session));
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
}
public void onStateChange(AtmosphereResourceEvent<HttpServletRequest, HttpServletResponse> event)
@@ -90,18 +110,35 @@
//do nothing
}
- public PushSession doConnect(String[] topicNames) {
- PushSession pushSession = getPushTracker().createPushSession();
+ public Session doConnect(String[] topicNames) {
+ Session pushSession = createSession(UUID.randomUUID().toString());
+ sessionManager.putPushSession(pushSession);
- TopicKey[] topicKeys = new TopicKey[topicNames.length];
for (int i = 0; i < topicNames.length; i++) {
- String topicName = topicNames[i];
+ TopicKey topicKey = new TopicKey(topicNames[i]);
- topicKeys[i] = new TopicKey(topicName);
+ try {
+ pushSession.subscribe(topicKey);
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
}
-
- //TODO - check permissions for channels
- pushSession.subscribe(topicKeys);
+
return pushSession;
}
+
+ protected abstract Session createSession(String key);
+
+ protected Request createRequest(AtmosphereResource<HttpServletRequest, HttpServletResponse> resource, Session session) {
+ return new RequestImpl(resource, session, worker);
+ }
+
+ public void init(ServletConfig servletConfig) throws Exception {
+ }
+
+ public void destroy() throws Exception {
+ sessionManager.destroy();
+ }
+
}
Copied: branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/push/impl/DefaultMessageDataSerializer.java (from rev 19530, branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/push/impl/DefaultMessageSerializer.java)
===================================================================
--- branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/push/impl/DefaultMessageDataSerializer.java (rev 0)
+++ branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/push/impl/DefaultMessageDataSerializer.java 2010-10-15 00:28:55 UTC (rev 19577)
@@ -0,0 +1,44 @@
+package org.richfaces.application.push.impl;
+/*
+ * 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.
+ */
+
+import org.ajax4jsf.javascript.ScriptUtils;
+import org.richfaces.application.push.MessageDataSerializer;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public final class DefaultMessageDataSerializer implements MessageDataSerializer {
+
+ private static final MessageDataSerializer INSTANCE = new DefaultMessageDataSerializer();
+
+ private DefaultMessageDataSerializer() {}
+
+ public static MessageDataSerializer instance() {
+ return INSTANCE;
+ }
+
+ public String serialize(Object data) {
+ return ScriptUtils.toScript(data);
+ }
+}
Deleted: branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/push/impl/DefaultMessageSerializer.java
===================================================================
--- branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/push/impl/DefaultMessageSerializer.java 2010-10-15 00:26:15 UTC (rev 19576)
+++ branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/push/impl/DefaultMessageSerializer.java 2010-10-15 00:28:55 UTC (rev 19577)
@@ -1,59 +0,0 @@
-package org.richfaces.application.push.impl;
-/*
- * 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.
- */
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.ajax4jsf.javascript.ScriptUtils;
-import org.richfaces.application.push.Message;
-import org.richfaces.application.push.MessageSerializer;
-
-/**
- * @author Nick Belaevski
- *
- */
-public final class DefaultMessageSerializer implements MessageSerializer {
-
- public static final String TOPIC_ATTRIBUTE = "topic";
-
- public static final String ATTRIBUTES_ATTRIBUTE = "attributes";
-
- public static final String DATA_ATTRIBUTE = "data";
-
- private static final MessageSerializer INSTANCE = new DefaultMessageSerializer();
-
- private DefaultMessageSerializer() {}
-
- public String serialize(Message message) {
- Map<String,Object> dataMap = new HashMap<String, Object>();
-
- dataMap.put(TOPIC_ATTRIBUTE, message.getTopicKey().getTopicName());
- dataMap.put(DATA_ATTRIBUTE, message.getData());
-
- return ScriptUtils.toScript(dataMap);
- }
-
- public static MessageSerializer instance() {
- return INSTANCE;
- }
-}
Deleted: branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/push/impl/MessagesContextImpl.java
===================================================================
--- branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/push/impl/MessagesContextImpl.java 2010-10-15 00:26:15 UTC (rev 19576)
+++ branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/push/impl/MessagesContextImpl.java 2010-10-15 00:28:55 UTC (rev 19577)
@@ -1,96 +0,0 @@
-/*
- * 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.application.push.impl;
-
-import java.util.List;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
-import java.util.concurrent.CopyOnWriteArrayList;
-
-import javax.servlet.ServletContext;
-
-import org.richfaces.application.push.Message;
-import org.richfaces.application.push.MessageListener;
-import org.richfaces.application.push.PublisherContext;
-import org.richfaces.application.push.SubscriptionContext;
-import org.richfaces.application.push.TopicKey;
-
-/**
- * @author Nick Belaevski
- *
- */
-public final class MessagesContextImpl implements SubscriptionContext, PublisherContext {
-
- private ConcurrentMap<TopicKey, List<MessageListener>> listenersMap = new ConcurrentHashMap<TopicKey, List<MessageListener>>();
-
- private MessagesContextImpl() {}
-
- public void addMessageListener(TopicKey topicKey, MessageListener listener) {
- List<MessageListener> listeners = listenersMap.get(topicKey);
- if (listeners == null) {
- List<MessageListener> newListenersList = new CopyOnWriteArrayList<MessageListener>();
-
- listeners = listenersMap.putIfAbsent(topicKey, newListenersList);
- if (listeners == null) {
- listeners = newListenersList;
- }
- }
-
- listeners.add(listener);
- }
-
- public void removeMessageListener(TopicKey topicKey, MessageListener listener) {
- List<MessageListener> listeners = listenersMap.get(topicKey);
- if (listeners != null) {
- listeners.remove(listener);
- }
- }
-
- public void publish(TopicKey topicKey, Object data) {
- Message message = new Message(topicKey);
- message.setData(data);
-
- publish(message);
- }
-
- public void publish(Message message) {
- List<MessageListener> listeners = listenersMap.get(message.getTopicKey());
- if (listeners != null) {
- for (MessageListener listener : listeners) {
- listener.onMessage(message);
- }
- }
- }
-
- public static MessagesContextImpl create(ServletContext servletContext) {
- MessagesContextImpl result = new MessagesContextImpl();
-
- servletContext.setAttribute(PublisherContext.ATTRIBUTE_NAME, result);
-
- return result;
- }
-
- public static void destroy(ServletContext servletContext) {
- servletContext.removeAttribute(PublisherContext.ATTRIBUTE_NAME);
- }
-
-}
Deleted: branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/push/impl/PushRequestWorker.java
===================================================================
--- branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/push/impl/PushRequestWorker.java 2010-10-15 00:26:15 UTC (rev 19576)
+++ branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/push/impl/PushRequestWorker.java 2010-10-15 00:28:55 UTC (rev 19577)
@@ -1,85 +0,0 @@
-/*
- * 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.application.push.impl;
-
-import java.io.IOException;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.ThreadFactory;
-import java.util.concurrent.atomic.AtomicInteger;
-
-/**
- * @author Nick Belaevski
- *
- */
-final class PushRequestWorker {
-
- private static final ThreadFactory DAEMON_THREADS_FACTORY = new ThreadFactory() {
-
- private final AtomicInteger threadsCounter = new AtomicInteger();
-
- public Thread newThread(Runnable r) {
- Thread t = new Thread(r, "rf-push-worker-thread-" + threadsCounter.getAndIncrement());
- t.setDaemon(true);
-
- return t;
- }
- };
-
- private final class Task implements Runnable {
-
- private RequestImpl request;
-
- public Task(RequestImpl request) {
- super();
- this.request = request;
- }
-
- public void run() {
- try {
- // TODO Auto-generated method stub
- try {
- request.writeMessages();
- request.resubmitToWorker();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- } catch (Throwable e) {
- // TODO: handle exception
- e.printStackTrace();
- }
- }
- }
-
- private ExecutorService executorService;
-
- public PushRequestWorker(int numThreads) {
- super();
-
- this.executorService = Executors.newFixedThreadPool(numThreads, DAEMON_THREADS_FACTORY);
- }
-
- public void submit(RequestImpl request) {
- executorService.submit(new Task(request));
- }
-}
Deleted: branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/push/impl/PushSessionImpl.java
===================================================================
--- branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/push/impl/PushSessionImpl.java 2010-10-15 00:26:15 UTC (rev 19576)
+++ branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/push/impl/PushSessionImpl.java 2010-10-15 00:28:55 UTC (rev 19577)
@@ -1,176 +0,0 @@
-/*
- * 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.application.push.impl;
-
-import java.io.IOException;
-import java.util.Queue;
-import java.util.concurrent.ConcurrentLinkedQueue;
-import java.util.concurrent.Delayed;
-import java.util.concurrent.TimeUnit;
-
-import org.richfaces.application.push.Message;
-import org.richfaces.application.push.MessageListener;
-import org.richfaces.application.push.PushSession;
-import org.richfaces.application.push.Request;
-import org.richfaces.application.push.RequestLifecycleListener;
-import org.richfaces.application.push.SubscriptionContext;
-import org.richfaces.application.push.TopicKey;
-
-/**
- * @author Nick Belaevski
- *
- */
-public class PushSessionImpl implements Delayed, PushSession, RequestLifecycleListener, MessageListener {
-
- private static final long EXPIRATION_DELAY = 45 * 1000;
-
- private final Queue<Message> messagesQueue = new ConcurrentLinkedQueue<Message>();
-
- private final PushSessionTrackerImpl pushTracker;
-
- private final String id;
-
- private volatile Request request = null;
-
- private volatile long expirationTime;
-
- private volatile TopicKey[] topics;
-
- public PushSessionImpl(PushSessionTrackerImpl pushTracker, String id) {
- super();
- this.pushTracker = pushTracker;
- this.id = id;
- resetExpirationTime();
- }
-
- private void resetExpirationTime() {
- expirationTime = System.currentTimeMillis() + EXPIRATION_DELAY;
- }
-
- public String getId() {
- return id;
- }
-
- public int compareTo(Delayed o) {
- return Long.valueOf(getDelay(TimeUnit.MILLISECONDS)).compareTo(o.getDelay(TimeUnit.MILLISECONDS));
- }
-
- public long getDelay(TimeUnit unit) {
- return unit.convert(expirationTime - System.currentTimeMillis(), TimeUnit.MILLISECONDS);
- }
-
- // ***** RequestLifecycleListener methods
-
- public void onSuspend(Request request) {
- if (!messagesQueue.isEmpty()) {
- request.submitMessages();
- }
- }
-
- public void onResume(Request request) {
- // TODO Auto-generated method stub
- try {
- disconnect();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
-
- public void onDisconnect(Request request) {
- // TODO Auto-generated method stub
- try {
- disconnect();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
-
- // ***** RequestLifecycleListener methods end
-
- // ***** MessageListener methods
-
- public void onMessage(Message message) {
- messagesQueue.add(message);
-
- if (request != null) {
- request.submitMessages();
- }
- }
-
- // ***** MessageListener methods end
-
- public synchronized void subscribe(TopicKey[] topics) {
- SubscriptionContext subscriptionContext = pushTracker.getSubscriptionContext();
-
- if (this.topics != null) {
- for (TopicKey topicKey : topics) {
- subscriptionContext.removeMessageListener(topicKey, this);
- }
- }
-
- this.topics = topics;
-
- for (TopicKey topicKey : topics) {
- subscriptionContext.addMessageListener(topicKey, this);
- }
-
- }
-
- public synchronized void connect(Request argRequest) throws IOException {
- if (request != null) {
- throw new IllegalStateException("Already connected!");
- }
-
- request = argRequest;
-
- pushTracker.onRequestConnected(this);
- request.addListener(this);
- request.suspend();
- }
-
- public synchronized void disconnect() throws IOException {
- if (request != null) {
- if (request.isSuspended()) {
- request.resume();
- }
-
- //TODO - request.removeListener(this) ?
- resetExpirationTime();
- pushTracker.onRequestDisconnected(this);
-
- request = null;
- }
- }
-
- public synchronized void destroy() {
- SubscriptionContext subscriptionContext = pushTracker.getSubscriptionContext();
- for (TopicKey topicKey : topics) {
- subscriptionContext.removeMessageListener(topicKey, this);
- }
- }
-
- public Iterable<Message> getMessages() {
- return messagesQueue;
- }
-}
Deleted: branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/push/impl/PushSessionTrackerImpl.java
===================================================================
--- branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/push/impl/PushSessionTrackerImpl.java 2010-10-15 00:26:15 UTC (rev 19576)
+++ branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/push/impl/PushSessionTrackerImpl.java 2010-10-15 00:28:55 UTC (rev 19577)
@@ -1,105 +0,0 @@
-/*
- * 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.application.push.impl;
-
-import java.util.UUID;
-import java.util.concurrent.ConcurrentMap;
-import java.util.concurrent.DelayQueue;
-
-import org.richfaces.application.push.PushSessionTracker;
-import org.richfaces.application.push.SubscriptionContext;
-
-import com.google.common.collect.MapMaker;
-
-/**
- * @author Nick Belaevski
- *
- */
-public class PushSessionTrackerImpl implements PushSessionTracker {
-
- private final class SessionsExpirationRunnable implements Runnable {
- public void run() {
- while (true) {
- try {
- PushSessionImpl pushSession = expirationQueue.take();
- pushSessionMap.remove(pushSession.getId());
- pushSession.destroy();
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
-
- }
- }
-
- private ConcurrentMap<String, PushSessionImpl> pushSessionMap = new MapMaker().makeMap();
-
- private DelayQueue<PushSessionImpl> expirationQueue = new DelayQueue<PushSessionImpl>();
-
- private SubscriptionContext subscriptionContext;
-
- public PushSessionTrackerImpl(SubscriptionContext subscriptionContext) {
- //TODO use configurable executor service
- Thread t = new Thread(new SessionsExpirationRunnable(), "rf-push-session-tracker");
- t.setDaemon(true);
- t.start();
-
- this.subscriptionContext = subscriptionContext;
- }
-
- public PushSessionImpl createPushSession() {
- while (true) {
- String uuid = UUID.randomUUID().toString();
- PushSessionImpl pushSession = new PushSessionImpl(this, uuid);
- if (pushSessionMap.putIfAbsent(uuid, pushSession) == null) {
- expirationQueue.put(pushSession);
-
- return pushSession;
- }
- }
- }
-
- public PushSessionImpl getPushSession(String id) {
- return pushSessionMap.get(id);
- }
-
- public void removePushSession(String id) {
- PushSessionImpl session = pushSessionMap.remove(id);
- if (session != null) {
- expirationQueue.remove(session);
- }
- }
-
- void onRequestConnected(PushSessionImpl pushSession) {
- expirationQueue.remove(pushSession);
- }
-
- void onRequestDisconnected(PushSessionImpl pushSession) {
- expirationQueue.add(pushSession);
- }
-
- protected SubscriptionContext getSubscriptionContext() {
- return subscriptionContext;
- }
-
-}
Modified: branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/push/impl/RequestImpl.java
===================================================================
--- branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/push/impl/RequestImpl.java 2010-10-15 00:26:15 UTC (rev 19576)
+++ branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/push/impl/RequestImpl.java 2010-10-15 00:28:55 UTC (rev 19577)
@@ -23,52 +23,58 @@
import java.io.IOException;
import java.io.PrintWriter;
-import java.util.ArrayList;
-import java.util.Iterator;
+import java.util.HashMap;
import java.util.List;
-import java.util.concurrent.locks.Lock;
-import java.util.concurrent.locks.ReentrantLock;
+import java.util.Map;
+import java.util.Queue;
+import java.util.concurrent.ConcurrentLinkedQueue;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.atomic.AtomicBoolean;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import org.ajax4jsf.javascript.JSLiteral;
+import org.ajax4jsf.javascript.ScriptUtils;
import org.atmosphere.cpr.AtmosphereEventLifecycle;
import org.atmosphere.cpr.AtmosphereResource;
import org.atmosphere.cpr.AtmosphereResourceEvent;
import org.atmosphere.cpr.AtmosphereResourceEventListener;
import org.atmosphere.websocket.WebSocketSupport;
import org.richfaces.application.push.Message;
-import org.richfaces.application.push.MessageSerializer;
-import org.richfaces.application.push.PushSession;
import org.richfaces.application.push.Request;
import org.richfaces.application.push.RequestLifecycleListener;
+import org.richfaces.application.push.Session;
-import com.google.common.collect.Iterables;
-
/**
* @author Nick Belaevski
*
*/
public class RequestImpl implements Request {
- private static final String DATA_WRAPPER_START = "[";
-
- private static final String DATA_WRAPPER_END = "]";
-
- private AtmosphereResource<HttpServletRequest, HttpServletResponse> atmosphereResource;
+ private static final class FlushMessagesTask implements Runnable {
+
+ private Request request;
- private List<RequestLifecycleListener> listeners = new ArrayList<RequestLifecycleListener>(1);
-
- private PushSession pushSession;
-
- private PushRequestWorker worker;
-
- private boolean submitted = false;
-
- private Lock submittedLock = new ReentrantLock();
-
- private AtmosphereResourceEventListener atmosphereListener = new AtmosphereResourceEventListener() {
+ public FlushMessagesTask(Request request) {
+ super();
+ this.request = request;
+ }
+ public void run() {
+ try {
+ request.flushMessages();
+ } catch (Throwable e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ }
+
+ private AtmosphereResourceEventListener atmosphereResourceListener = new AtmosphereResourceEventListener() {
+
public void onSuspend(AtmosphereResourceEvent<HttpServletRequest, HttpServletResponse> event) {
for (RequestLifecycleListener listener : listeners) {
listener.onSuspend(RequestImpl.this);
@@ -78,7 +84,7 @@
public void onResume(AtmosphereResourceEvent<HttpServletRequest, HttpServletResponse> event) {
for (RequestLifecycleListener listener : listeners) {
listener.onResume(RequestImpl.this);
- }
+ }
}
public void onDisconnect(AtmosphereResourceEvent<HttpServletRequest, HttpServletResponse> event) {
@@ -93,119 +99,116 @@
}
};
- public RequestImpl(AtmosphereResource<HttpServletRequest, HttpServletResponse> resource, PushSession pushSession,
- PushRequestWorker worker) {
+ private final AtmosphereResource<HttpServletRequest, HttpServletResponse> atmosphereResource;
+ private final Session session;
+
+ private final ExecutorService executorService;
+
+ private final Queue<Message> messagesQueue = new ConcurrentLinkedQueue<Message>();
+
+ private final List<RequestLifecycleListener> listeners = new CopyOnWriteArrayList<RequestLifecycleListener>();
+
+ private AtomicBoolean submitted = new AtomicBoolean(false);
+
+ public RequestImpl(AtmosphereResource<HttpServletRequest, HttpServletResponse> atmosphereResource, Session session,
+ ExecutorService executorService) {
+
super();
- this.atmosphereResource = resource;
- ((AtmosphereEventLifecycle) atmosphereResource).addEventListener(atmosphereListener);
- this.pushSession = pushSession;
- this.worker = worker;
+ this.atmosphereResource = atmosphereResource;
+
+ ((AtmosphereEventLifecycle) atmosphereResource).addEventListener(atmosphereResourceListener);
+
+ this.session = session;
+ this.executorService = executorService;
}
-
- public void addListener(RequestLifecycleListener listener) {
- listeners.add(listener);
- }
-
- public void removeListener(RequestLifecycleListener listener) {
- listeners.remove(listener);
- }
- public void submitMessages() {
- try {
- submittedLock.lock();
-
- if (!submitted) {
- submitted = true;
- worker.submit(this);
- }
- } finally {
- submittedLock.unlock();
+ private void submitToWorker() {
+ if (submitted.compareAndSet(false, true)) {
+ executorService.submit(new FlushMessagesTask(this));
}
}
-
- void resubmitToWorker() {
- if (isPolling()) {
- return;
- }
- try {
- submittedLock.lock();
- if (!Iterables.isEmpty(pushSession.getMessages())) {
- worker.submit(this);
- } else {
- submitted = false;
- }
- } finally {
- submittedLock.unlock();
- }
- }
-
- void writeMessages() throws IOException {
- HttpServletResponse response = atmosphereResource.getResponse();
-
- PrintWriter writer = response.getWriter();
-
+ private String serializeMessages() {
StringBuilder sb = new StringBuilder();
- boolean isFirstMessage = true;
+ sb.append("[");
+
+ boolean isFirstElement = true;
- Iterable<Message> messages = pushSession.getMessages();
- for (Iterator<Message> itr = messages.iterator(); itr.hasNext(); ) {
- if (isFirstMessage) {
- sb.append(DATA_WRAPPER_START);
+ while (true) {
+ Message message = messagesQueue.poll();
+ if (message == null) {
+ break;
}
-
- Message message = itr.next();
- itr.remove();
- sb.append(getMessageSerializer(message).serialize(message));
-
- if (!isFirstMessage) {
+
+ if (isFirstElement) {
+ isFirstElement = false;
+ } else {
sb.append(", ");
- } else {
- isFirstMessage = false;
}
- }
-
- if (sb.length() != 0) {
- sb.append(DATA_WRAPPER_END);
- writer.write(sb.toString());
+ //TODO - use MessageSerializer
+ String messageDataString = DefaultMessageDataSerializer.instance().serialize(message.getData());
- if (isPolling()) {
- resume();
- }
+ Map<String, Object> map = new HashMap<String, Object>(2);
+
+ map.put("data", new JSLiteral(messageDataString));
+ map.put("topic", message.getTopicKey().getTopicName());
+
+ sb.append(ScriptUtils.toScript(map));
}
+
+ sb.append("]");
+
+ return sb.toString();
}
+
+ public void flushMessages() throws IOException {
+ for (RequestLifecycleListener listener : listeners) {
+ listener.onFlush(this);
+ }
+
+ String serializedMessages = serializeMessages();
+ PrintWriter writer = atmosphereResource.getResponse().getWriter();
+ writer.write(serializedMessages);
+ writer.flush();
+
+ submitted.compareAndSet(true, false);
- public void suspend() throws IOException {
- if (!isSuspended()) {
- //TODO - customize interval
- atmosphereResource.suspend();
+ if (isPolling()) {
+ atmosphereResource.resume();
+ } else if (!messagesQueue.isEmpty()) {
+ submitToWorker();
}
}
+ public void postMessage(Message message) {
+ messagesQueue.add(message);
+ submitToWorker();
+ }
+
+ public void addListener(RequestLifecycleListener listener) {
+ listeners.add(listener);
+ }
+
+ public void removeListener(RequestLifecycleListener listener) {
+ listeners.remove(listener);
+ }
+
+ public void suspend() throws IOException {
+ atmosphereResource.suspend(-1, isPolling());
+ }
+
public void resume() throws IOException {
- if (isSuspended()) {
- atmosphereResource.resume();
- }
+ atmosphereResource.resume();
}
public boolean isSuspended() {
return atmosphereResource.getAtmosphereResourceEvent().isSuspended();
}
- private MessageSerializer getMessageSerializer(Message message) {
- MessageSerializer serializer = (MessageSerializer) message.getAttribute(MessageSerializer.MESSAGE_ATTRIBUTE_NAME);
-
- if (serializer == null) {
- serializer = DefaultMessageSerializer.instance();
- }
-
- return serializer;
- }
-
public boolean isPolling() {
HttpServletRequest req = atmosphereResource.getRequest();
boolean isWebsocket = req.getAttribute(WebSocketSupport.WEBSOCKET_SUSPEND) != null ||
@@ -215,7 +218,8 @@
return !isWebsocket;
}
- public PushSession getPushSession() {
- return pushSession;
+ public Session getSession() {
+ return session;
}
+
}
Copied: branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/push/impl/SessionManagerImpl.java (from rev 19562, branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/push/impl/PushSessionTrackerImpl.java)
===================================================================
--- branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/push/impl/SessionManagerImpl.java (rev 0)
+++ branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/push/impl/SessionManagerImpl.java 2010-10-15 00:28:55 UTC (rev 19577)
@@ -0,0 +1,171 @@
+/*
+ * 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.application.push.impl;
+
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.DelayQueue;
+import java.util.concurrent.Delayed;
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.TimeUnit;
+
+import org.richfaces.application.push.Session;
+import org.richfaces.application.push.SessionListener;
+import org.richfaces.application.push.SessionManager;
+
+import com.google.common.collect.MapMaker;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class SessionManagerImpl implements SessionManager {
+
+ //TODO - implement queue around sessions properly
+ private final class DelayedSessionHolder implements Delayed {
+
+ private final Session session;
+
+ public DelayedSessionHolder(Session session) {
+ super();
+ this.session = session;
+ }
+
+ public int compareTo(Delayed o) {
+ return Long.valueOf(getDelay(TimeUnit.MILLISECONDS)).compareTo(o.getDelay(TimeUnit.MILLISECONDS));
+ }
+
+ public long getDelay(TimeUnit unit) {
+ return unit.convert(session.getLastAccessedTime() + session.getMaxInactiveInterval() - System.currentTimeMillis(),
+ TimeUnit.MILLISECONDS);
+ }
+
+ public Session getSession() {
+ return session;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + getOuterType().hashCode();
+ result = prime * result + ((session == null) ? 0 : session.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ DelayedSessionHolder other = (DelayedSessionHolder) obj;
+ if (!getOuterType().equals(other.getOuterType())) {
+ return false;
+ }
+ if (session == null) {
+ if (other.session != null) {
+ return false;
+ }
+ } else if (!session.equals(other.session)) {
+ return false;
+ }
+ return true;
+ }
+
+ private SessionManagerImpl getOuterType() {
+ return SessionManagerImpl.this;
+ }
+ }
+
+ private final class SessionsExpirationRunnable implements Runnable {
+ public void run() {
+ while (true) {
+ try {
+ DelayedSessionHolder sessionHolder = expirationQueue.take();
+ sessionMap.remove(sessionHolder.getSession().getId());
+ sessionHolder.getSession().destroy();
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ }
+ }
+
+ private final SessionListener sessionListener = new SessionListener() {
+
+ public void onSessionDestroyed(Session session) {
+ // TODO Auto-generated method stub
+ removePushSession(session.getId());
+ }
+
+ public void onRequestDisconnected(Session session) {
+ expirationQueue.add(new DelayedSessionHolder(session));
+ }
+
+ public void onRequestConnected(Session session) {
+ expirationQueue.remove(new DelayedSessionHolder(session));
+ }
+ };
+
+ private ConcurrentMap<String, Session> sessionMap = new MapMaker().makeMap();
+
+ private DelayQueue<DelayedSessionHolder> expirationQueue = new DelayQueue<DelayedSessionHolder>();
+
+ public SessionManagerImpl(ThreadFactory threadFactory) {
+ threadFactory.newThread(new SessionsExpirationRunnable()).start();
+ }
+
+ public Session getPushSession(String id) {
+ return sessionMap.get(id);
+ }
+
+ public void removePushSession(String id) {
+ Session session = sessionMap.remove(id);
+ if (session != null) {
+ session.removeSessionListener(sessionListener);
+ expirationQueue.remove(new DelayedSessionHolder(session));
+ }
+ }
+
+ public void destroy() {
+ //TODO notify all session
+ expirationQueue.clear();
+ sessionMap.clear();
+ }
+
+ public void putPushSession(Session session) throws IllegalStateException {
+ Session existingSession = sessionMap.putIfAbsent(session.getId(), session);
+ if (existingSession != null) {
+ throw new IllegalStateException();
+ }
+
+ expirationQueue.add(new DelayedSessionHolder(session));
+ session.addSessionListener(sessionListener);
+ }
+}
Added: branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/push/impl/jms/MessagingContext.java
===================================================================
--- branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/push/impl/jms/MessagingContext.java (rev 0)
+++ branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/push/impl/jms/MessagingContext.java 2010-10-15 00:28:55 UTC (rev 19577)
@@ -0,0 +1,122 @@
+/*
+ * 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.application.push.impl.jms;
+
+import java.util.UUID;
+
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.JMSException;
+import javax.jms.Session;
+import javax.jms.Topic;
+import javax.naming.InitialContext;
+import javax.naming.Name;
+import javax.naming.NamingException;
+
+import org.richfaces.application.push.TopicKey;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class MessagingContext {
+
+ private final InitialContext initialContext;
+
+ private final Name connectionFactoryName;
+
+ private final Name topicsRootName;
+
+ private final String applicationName;
+
+ private final String username;
+
+ private final String password;
+
+ private Connection connection;
+
+ public MessagingContext(InitialContext initialContext, Name connectionFactoryName, Name topicsRootName,
+ String applicationName) {
+
+ this(initialContext, connectionFactoryName, topicsRootName, applicationName, null, null);
+ }
+
+ public MessagingContext(InitialContext initialContext, Name connectionFactoryName, Name topicsRootName,
+ String applicationName, String username, String password) {
+
+ super();
+ this.initialContext = initialContext;
+ this.connectionFactoryName = connectionFactoryName;
+ this.topicsRootName = topicsRootName;
+ this.applicationName = applicationName;
+ this.username = username;
+ this.password = password;
+ }
+
+ private Name appendToName(Name name, String comp) throws NamingException {
+ Name clonedName = (Name) name.clone();
+ return clonedName.add(comp);
+ }
+
+ public void start() throws Exception {
+ ConnectionFactory connectionFactory = (ConnectionFactory) initialContext.lookup(connectionFactoryName);
+
+ connection = connectionFactory.createConnection(username, password);
+
+ //TODO - review
+ try {
+ //durable subscription requires ClientID to be set
+ connection.setClientID(UUID.randomUUID().toString());
+ } catch (IllegalStateException e) {
+ //ignore - clientId has already been set
+ }
+
+ connection.start();
+ }
+
+ public void stop() throws Exception {
+ connection.stop();
+ connection = null;
+ }
+
+ public Connection getConnection() {
+ if (connection == null) {
+ throw new IllegalStateException("connection is absent");
+ }
+
+ return connection;
+ }
+
+ public Topic lookup(TopicKey topicKey) throws NamingException {
+ Name topicName = appendToName(topicsRootName, topicKey.getTopicName());
+
+ return (Topic) initialContext.lookup(topicName);
+ }
+
+ public Session createSession() throws JMSException {
+ return connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ }
+
+ public String getApplicationName() {
+ return applicationName;
+ }
+}
Added: branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/push/impl/jms/PublisherContextImpl.java
===================================================================
--- branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/push/impl/jms/PublisherContextImpl.java (rev 0)
+++ branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/push/impl/jms/PublisherContextImpl.java 2010-10-15 00:28:55 UTC (rev 19577)
@@ -0,0 +1,75 @@
+/*
+ * 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.application.push.impl.jms;
+
+import java.io.Serializable;
+
+import javax.jms.JMSException;
+import javax.jms.MessageProducer;
+import javax.jms.ObjectMessage;
+import javax.jms.Session;
+import javax.naming.NamingException;
+
+import org.richfaces.application.push.PublisherContext;
+import org.richfaces.application.push.TopicKey;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class PublisherContextImpl implements PublisherContext {
+
+ private MessagingContext messagingContext;
+
+ public PublisherContextImpl(MessagingContext messagingContext) {
+ super();
+ this.messagingContext = messagingContext;
+ }
+
+ public void publish(TopicKey topicKey, Object data) {
+ Session session = null;
+ try {
+ session = messagingContext.createSession();
+ MessageProducer producer = session.createProducer(messagingContext.lookup(topicKey));
+
+ ObjectMessage objectMessage = session.createObjectMessage();
+ objectMessage.setObject((Serializable) data);
+
+ producer.send(objectMessage);
+ } catch (JMSException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (NamingException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } finally {
+ if (session != null) {
+ try {
+ session.close();
+ } catch (JMSException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+}
Added: branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/push/impl/jms/PushHandlerImpl.java
===================================================================
--- branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/push/impl/jms/PushHandlerImpl.java (rev 0)
+++ branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/push/impl/jms/PushHandlerImpl.java 2010-10-15 00:28:55 UTC (rev 19577)
@@ -0,0 +1,77 @@
+/*
+ * 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.application.push.impl.jms;
+
+import javax.naming.CompositeName;
+import javax.naming.InitialContext;
+import javax.naming.Name;
+import javax.servlet.ServletConfig;
+
+import org.richfaces.application.push.PublisherContext;
+import org.richfaces.application.push.Session;
+import org.richfaces.application.push.impl.AtmospherePushHandler;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class PushHandlerImpl extends AtmospherePushHandler {
+
+ private MessagingContext messagingContext;
+
+ private ServletConfig servletConfig;
+
+ @Override
+ protected Session createSession(String key) {
+ return new SessionImpl(key, messagingContext);
+ }
+
+ @Override
+ public void init(ServletConfig servletConfig) throws Exception {
+ super.init(servletConfig);
+
+ this.servletConfig = servletConfig;
+
+ InitialContext initialContext = new InitialContext();
+ Name cnfName = new CompositeName("/ConnectionFactory");
+ Name topicsRootName = new CompositeName("/topic");
+
+ messagingContext = new MessagingContext(initialContext, cnfName, topicsRootName,
+ servletConfig.getServletContext().getContextPath());
+
+ messagingContext.start();
+
+ PublisherContext publisherContext = new PublisherContextImpl(messagingContext);
+ servletConfig.getServletContext().setAttribute(PublisherContext.ATTRIBUTE_NAME, publisherContext);
+ }
+
+ @Override
+ public void destroy() throws Exception {
+ super.destroy();
+
+ this.servletConfig.getServletContext().removeAttribute(PublisherContext.ATTRIBUTE_NAME);
+ this.servletConfig = null;
+
+ messagingContext.stop();
+ messagingContext = null;
+ }
+}
Added: branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/push/impl/jms/SessionImpl.java
===================================================================
--- branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/push/impl/jms/SessionImpl.java (rev 0)
+++ branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/push/impl/jms/SessionImpl.java 2010-10-15 00:28:55 UTC (rev 19577)
@@ -0,0 +1,192 @@
+/*
+ * 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.application.push.impl.jms;
+
+import java.util.Collection;
+import java.util.HashSet;
+
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageListener;
+import javax.jms.ObjectMessage;
+import javax.jms.Session;
+import javax.jms.Topic;
+import javax.jms.TopicSubscriber;
+
+import org.richfaces.application.push.Request;
+import org.richfaces.application.push.RequestLifecycleListener;
+import org.richfaces.application.push.TopicKey;
+import org.richfaces.application.push.impl.AbstractSession;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class SessionImpl extends AbstractSession implements RequestLifecycleListener, MessageListener {
+
+ private MessagingContext messagingContext;
+
+ private Collection<TopicKey> subscribedTopics = new HashSet<TopicKey>();
+
+ private volatile Session jmsSession;
+
+ public SessionImpl(String id, MessagingContext messagingContext) {
+ super(id);
+
+ this.messagingContext = messagingContext;
+ }
+
+ private String getSubscriptionClientId(TopicKey topic) {
+ //TODO add application name
+ return "rf-push:" + messagingContext.getApplicationName() + ":" + topic.getTopicName() + ":" + getId();
+ }
+
+ public void subscribe(TopicKey topic) throws Exception {
+ Session session = null;
+ try {
+ session = messagingContext.createSession();
+
+ //TODO send event to check subscription permissions
+ session.createDurableSubscriber(messagingContext.lookup(topic), getSubscriptionClientId(topic));
+ subscribedTopics.add(topic);
+
+ } finally {
+ if (session != null) {
+ try {
+ session.close();
+ } catch (JMSException e) {
+ // TODO: handle exception
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+
+ @Override
+ public void destroy() {
+ // TODO Auto-generated method stub
+ super.destroy();
+
+ //TODO remove subscriptions
+ }
+
+ @Override
+ public void connect(Request request) throws Exception {
+ super.connect(request);
+
+ request.addListener(this);
+
+ jmsSession = messagingContext.createSession();
+
+ for (TopicKey topicKey : subscribedTopics) {
+ Topic topic = messagingContext.lookup(topicKey);
+ String subscriptionId = getSubscriptionClientId(topicKey);
+
+ TopicSubscriber subscriber = jmsSession.createDurableSubscriber(topic, subscriptionId);
+ subscriber.setMessageListener(this);
+ }
+ }
+
+ @Override
+ public void disconnect(Request request) throws Exception {
+ jmsSession.close();
+ jmsSession = null;
+
+ request.removeListener(this);
+
+ super.disconnect(request);
+ }
+
+ /* (non-Javadoc)
+ * @see org.richfaces.application.push.RequestLifecycleListener#onFlush(org.richfaces.application.push.Request)
+ */
+ public void onFlush(Request request) {
+ if (request.isPolling()) {
+ try {
+ jmsSession.close();
+ } catch (JMSException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.richfaces.application.push.RequestLifecycleListener#onSuspend(org.richfaces.application.push.Request)
+ */
+ public void onSuspend(Request request) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.richfaces.application.push.RequestLifecycleListener#onDisconnect(org.richfaces.application.push.Request)
+ */
+ public void onDisconnect(Request request) {
+ // TODO Auto-generated method stub
+
+ try {
+ disconnect(request);
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.richfaces.application.push.RequestLifecycleListener#onResume(org.richfaces.application.push.Request)
+ */
+ public void onResume(Request request) {
+ // TODO Auto-generated method stub
+ try {
+ disconnect(request);
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see javax.jms.MessageListener#onMessage(javax.jms.Message)
+ */
+ public void onMessage(Message message) {
+ if (!(message instanceof ObjectMessage)) {
+ //TODO log
+ return;
+ }
+
+ try {
+ ObjectMessage objectMessage = (ObjectMessage) message;
+ String topicName = ((Topic) objectMessage.getJMSDestination()).getTopicName();
+
+ org.richfaces.application.push.Message pushMessage = new org.richfaces.application.push.Message(new TopicKey(topicName));
+ pushMessage.setData(objectMessage.getObject());
+
+ getRequest().postMessage(pushMessage);
+
+ objectMessage.acknowledge();
+ } catch (JMSException e) {
+ // TODO: handle exception
+ e.printStackTrace();
+ }
+ }
+}
Modified: branches/RF-7817/push-redesign/src/main/java/org/richfaces/webapp/PushServlet.java
===================================================================
--- branches/RF-7817/push-redesign/src/main/java/org/richfaces/webapp/PushServlet.java 2010-10-15 00:26:15 UTC (rev 19576)
+++ branches/RF-7817/push-redesign/src/main/java/org/richfaces/webapp/PushServlet.java 2010-10-15 00:28:55 UTC (rev 19577)
@@ -25,15 +25,14 @@
import java.lang.reflect.InvocationTargetException;
import javax.servlet.ServletConfig;
-import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.atmosphere.cpr.AtmosphereServlet;
-import org.richfaces.application.push.PushSession;
+import org.richfaces.application.push.Session;
import org.richfaces.application.push.impl.AtmospherePushHandler;
-import org.richfaces.application.push.impl.MessagesContextImpl;
+import org.richfaces.application.push.impl.jms.PushHandlerImpl;
/**
* @author Nick Belaevski
@@ -42,9 +41,6 @@
//TODO override broadcaster
public class PushServlet extends AtmosphereServlet {
- /**
- *
- */
private static final String PUSH_HUB_MAPPING = "/push/hub/*";
private static final long serialVersionUID = 7616370505508715222L;
@@ -53,34 +49,39 @@
private AtmospherePushHandler pushHandler;
- private ServletContext servletContext;
-
@Override
public void init(ServletConfig config) throws ServletException {
super.init(config);
-
- servletContext = config.getServletContext();
- MessagesContextImpl messagesContext = MessagesContextImpl.create(servletContext);
-
- pushHandler = new AtmospherePushHandler(messagesContext);
+
+ pushHandler = new PushHandlerImpl();
+ try {
+ pushHandler.init(config);
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
addAtmosphereHandler(PUSH_HUB_MAPPING, pushHandler);
-
}
@Override
public void destroy() {
super.destroy();
- MessagesContextImpl.destroy(servletContext);
-
+ try {
+ pushHandler.destroy();
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
pushHandler = null;
+
removeAtmosphereHandler(PUSH_HUB_MAPPING);
}
@Override
public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String[] topicNames = req.getParameterValues(PUSH_TOPIC_PARAM);
- PushSession pushSession = pushHandler.doConnect(topicNames);
+ Session pushSession = pushHandler.doConnect(topicNames);
resp.setStatus(HttpServletResponse.SC_OK);
resp.getWriter().write(pushSession.getId());
Modified: branches/RF-7817/push-redesign-app/pom.xml
===================================================================
--- branches/RF-7817/push-redesign-app/pom.xml 2010-10-15 00:26:15 UTC (rev 19576)
+++ branches/RF-7817/push-redesign-app/pom.xml 2010-10-15 00:28:55 UTC (rev 19577)
@@ -7,7 +7,7 @@
<version>0.0.1-SNAPSHOT</version>
<name>push-redesign-app Maven Webapp</name>
<url>http://maven.apache.org</url>
-
+
<repositories>
<repository>
<id>sonatype.snapshots</id>
@@ -17,9 +17,45 @@
</snapshots>
</repository>
</repositories>
-
+
+ <properties>
+ <hornetq.version>2.1.2.Final</hornetq.version>
+ </properties>
+
<dependencies>
<dependency>
+ <groupId>org.hornetq</groupId>
+ <artifactId>hornetq-core</artifactId>
+ <version>${hornetq.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.hornetq</groupId>
+ <artifactId>hornetq-jms</artifactId>
+ <version>${hornetq.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.hornetq</groupId>
+ <artifactId>hornetq-logging</artifactId>
+ <version>${hornetq.version}</version>
+ </dependency>
+ <!-- dependency>
+ <groupId>org.hornetq</groupId>
+ <artifactId>hornetq-transports</artifactId>
+ <version>2.1.0.r9031</version>
+ </dependency -->
+ <dependency>
+ <groupId>org.jboss.netty</groupId>
+ <artifactId>netty</artifactId>
+ <version>3.2.2.Final</version>
+ </dependency>
+ <dependency>
+ <groupId>javax.jms</groupId>
+ <artifactId>jms</artifactId>
+ <version>1.1</version>
+ </dependency>
+
+
+ <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.7</version>
@@ -31,11 +67,6 @@
<version>3.0-alpha-1</version>
<scope>provided</scope>
</dependency>
- <!-- dependency>
- <groupId>org.eclipse.jetty</groupId>
- <artifactId>jetty-websocket</artifactId>
- <version>8.0.0.M1</version>
- </dependency -->
<dependency>
<groupId>org.atmosphere</groupId>
<artifactId>atmosphere-runtime</artifactId>
@@ -77,11 +108,28 @@
<target>1.6</target>
</configuration>
</plugin>
- <plugin>
- <groupId>org.mortbay.jetty</groupId>
- <artifactId>jetty-maven-plugin</artifactId>
- <version>8.0.0.M1</version>
- </plugin>
</plugins>
</build>
+
+ <profiles>
+ <profile>
+ <id>jetty</id>
+ <dependencies>
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-websocket</artifactId>
+ <version>8.0.0.M1</version>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-maven-plugin</artifactId>
+ <version>8.0.0.M1</version>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
</project>
Added: branches/RF-7817/push-redesign-app/src/main/java/demo/HornetQInitializer.java
===================================================================
--- branches/RF-7817/push-redesign-app/src/main/java/demo/HornetQInitializer.java (rev 0)
+++ branches/RF-7817/push-redesign-app/src/main/java/demo/HornetQInitializer.java 2010-10-15 00:28:55 UTC (rev 19577)
@@ -0,0 +1,120 @@
+/*
+ * 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 demo;
+
+import java.util.HashSet;
+
+import javax.faces.application.Application;
+import javax.faces.context.FacesContext;
+import javax.faces.event.AbortProcessingException;
+import javax.faces.event.PostConstructApplicationEvent;
+import javax.faces.event.PreDestroyApplicationEvent;
+import javax.faces.event.SystemEvent;
+import javax.faces.event.SystemEventListener;
+import javax.naming.InitialContext;
+
+import org.hornetq.api.core.TransportConfiguration;
+import org.hornetq.core.config.Configuration;
+import org.hornetq.core.config.impl.ConfigurationImpl;
+import org.hornetq.core.remoting.impl.netty.NettyAcceptorFactory;
+import org.hornetq.core.remoting.impl.netty.NettyConnectorFactory;
+import org.hornetq.core.server.HornetQServer;
+import org.hornetq.core.server.HornetQServers;
+import org.hornetq.jms.server.JMSServerManager;
+import org.hornetq.jms.server.impl.JMSServerManagerImpl;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class HornetQInitializer implements SystemEventListener {
+
+ private JMSServerManager serverManager;
+
+ @Override
+ public void processEvent(SystemEvent event) throws AbortProcessingException {
+ if (event instanceof PostConstructApplicationEvent) {
+ try {
+ startHornetQ();
+ } catch (Exception e) {
+ throw new AbortProcessingException(e);
+ }
+
+ Application application = FacesContext.getCurrentInstance().getApplication();
+ application.subscribeToEvent(PreDestroyApplicationEvent.class, this);
+ } else {
+ try {
+ stopHornetQ();
+ } catch (Exception e) {
+ throw new AbortProcessingException(e);
+ }
+ }
+ }
+
+ /**
+ * @throws Exception
+ *
+ */
+ private void stopHornetQ() throws Exception {
+ serverManager.stop();
+ serverManager = null;
+ }
+
+ /**
+ * @throws Exception
+ *
+ */
+ private void startHornetQ() throws Exception {
+ // Step 2. Create the Configuration, and set the properties accordingly
+ Configuration configuration = new ConfigurationImpl();
+ configuration.setPersistenceEnabled(false);
+ configuration.setSecurityEnabled(false);
+
+ TransportConfiguration transpConf = new TransportConfiguration(NettyAcceptorFactory.class.getName());
+
+ HashSet<TransportConfiguration> setTransp = new HashSet<TransportConfiguration>();
+ setTransp.add(transpConf);
+
+ configuration.setAcceptorConfigurations(setTransp);
+
+ // Step 3. Create and start the server
+ HornetQServer server = HornetQServers.newHornetQServer(configuration);
+
+ serverManager = new JMSServerManagerImpl(server);
+
+ //if you want to use JNDI, simple inject a context here or don't call this method and make sure the JNDI parameters are set.
+ serverManager.setContext(new InitialContext());
+ serverManager.start();
+
+ serverManager.createConnectionFactory("ConnectionFactory", new TransportConfiguration(NettyConnectorFactory.class.getName()),
+ "ConnectionFactory");
+
+ serverManager.createTopic(false, "chat", "/topic/chat");
+ serverManager.createTopic(false, "info", "/topic/info");
+ }
+
+ @Override
+ public boolean isListenerForSource(Object source) {
+ return true;
+ }
+
+}
Added: branches/RF-7817/push-redesign-app/src/main/java/demo/TopicsInitializer.java
===================================================================
--- branches/RF-7817/push-redesign-app/src/main/java/demo/TopicsInitializer.java (rev 0)
+++ branches/RF-7817/push-redesign-app/src/main/java/demo/TopicsInitializer.java 2010-10-15 00:28:55 UTC (rev 19577)
@@ -0,0 +1,54 @@
+/*
+ * 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 demo;
+
+import javax.faces.event.AbortProcessingException;
+import javax.faces.event.SystemEvent;
+import javax.faces.event.SystemEventListener;
+
+import org.richfaces.application.ServiceTracker;
+import org.richfaces.application.push.Topic;
+import org.richfaces.application.push.TopicKey;
+import org.richfaces.application.push.TopicsContext;
+import org.richfaces.application.push.impl.DefaultMessageDataSerializer;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class TopicsInitializer implements SystemEventListener {
+
+ @Override
+ public void processEvent(SystemEvent event) throws AbortProcessingException {
+ TopicsContext topicsContext = ServiceTracker.getService(TopicsContext.class);
+
+ Topic topic = topicsContext.getOrCreateTopic(new TopicKey("chatTopic"));
+
+ topic.setMessageSerializer(DefaultMessageDataSerializer.instance());
+ }
+
+ @Override
+ public boolean isListenerForSource(Object source) {
+ return true;
+ }
+
+}
Modified: branches/RF-7817/push-redesign-app/src/main/webapp/WEB-INF/faces-config.xml
===================================================================
--- branches/RF-7817/push-redesign-app/src/main/webapp/WEB-INF/faces-config.xml 2010-10-15 00:26:15 UTC (rev 19576)
+++ branches/RF-7817/push-redesign-app/src/main/webapp/WEB-INF/faces-config.xml 2010-10-15 00:28:55 UTC (rev 19577)
@@ -1,6 +1,18 @@
<?xml version='1.0' encoding='UTF-8'?>
-<faces-config xmlns="http://java.sun.com/xml/ns/javaee"
- version="2.0">
+<faces-config version="2.0" xmlns="http://java.sun.com/xml/ns/javaee"
+ xmlns:xi="http://www.w3.org/2001/XInclude"
+ 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-facesconfig_2_0.xsd">
+ <application>
+ <system-event-listener>
+ <system-event-listener-class>demo.HornetQInitializer</system-event-listener-class>
+ <system-event-class>javax.faces.event.PostConstructApplicationEvent</system-event-class>
+ </system-event-listener>
+ <system-event-listener>
+ <system-event-listener-class>demo.TopicsInitializer</system-event-listener-class>
+ <system-event-class>javax.faces.event.PostConstructApplicationEvent</system-event-class>
+ </system-event-listener>
+ </application>
+
</faces-config>
\ No newline at end of file
Modified: branches/RF-7817/push-redesign-app/src/main/webapp/WEB-INF/web.xml
===================================================================
--- branches/RF-7817/push-redesign-app/src/main/webapp/WEB-INF/web.xml 2010-10-15 00:26:15 UTC (rev 19576)
+++ branches/RF-7817/push-redesign-app/src/main/webapp/WEB-INF/web.xml 2010-10-15 00:28:55 UTC (rev 19577)
@@ -9,9 +9,16 @@
<param-value>Development</param-value>
</context-param>
+ <listener>
+ <listener-class>com.sun.faces.config.ConfigureListener</listener-class>
+ </listener>
<servlet>
<servlet-name>push</servlet-name>
<servlet-class>org.richfaces.webapp.PushServlet</servlet-class>
+ <init-param>
+ <param-name>org.atmosphere.useWebSocket</param-name>
+ <param-value>true</param-value>
+ </init-param>
<load-on-startup>1</load-on-startup>
<async-supported>true</async-supported>
</servlet>
Modified: branches/RF-7817/ui/common/ui/checkstyle-suppressions.xml
===================================================================
--- branches/RF-7817/ui/common/ui/checkstyle-suppressions.xml 2010-10-15 00:26:15 UTC (rev 19576)
+++ branches/RF-7817/ui/common/ui/checkstyle-suppressions.xml 2010-10-15 00:28:55 UTC (rev 19577)
@@ -33,4 +33,8 @@
<!-- TODO it is hot fix for building process, this files belong to the ui/output/trunk/panela/ui module,
and must be removed from here -->
<suppress checks="IllegalCatch" files="AbstractTogglePanel.java" />
-</suppressions>
+
+ <!-- TODO it is hot fix for building process, this files belong to the push-redesign module,
+ and must be removed from here -->
+ <suppress checks="IllegalCatch" files="RequestImpl.java" />
+</suppressions>
\ No newline at end of file
Modified: branches/RF-7817/ui/output/ui/checkstyle-suppressions.xml
===================================================================
--- branches/RF-7817/ui/output/ui/checkstyle-suppressions.xml 2010-10-15 00:26:15 UTC (rev 19576)
+++ branches/RF-7817/ui/output/ui/checkstyle-suppressions.xml 2010-10-15 00:28:55 UTC (rev 19577)
@@ -33,4 +33,8 @@
<!-- TODO it is hot fix for building process, this files belong to the ui/output/trunk/panela/ui module,
and must be removed from here -->
<suppress checks="IllegalCatch" files="AbstractTogglePanel.java" />
+
+ <!-- TODO it is hot fix for building process, this files belong to the push-redesign module,
+ and must be removed from here -->
+ <suppress checks="IllegalCatch" files="RequestImpl.java" />
</suppressions>
13 years, 8 months
JBoss Rich Faces SVN: r19576 - branches/RF-7817/core/api/src/main/java/org/richfaces/application/push.
by richfaces-svn-commits@lists.jboss.org
Author: nbelaevski
Date: 2010-10-14 20:26:15 -0400 (Thu, 14 Oct 2010)
New Revision: 19576
Modified:
branches/RF-7817/core/api/src/main/java/org/richfaces/application/push/Message.java
branches/RF-7817/core/api/src/main/java/org/richfaces/application/push/PublisherContext.java
branches/RF-7817/core/api/src/main/java/org/richfaces/application/push/Request.java
branches/RF-7817/core/api/src/main/java/org/richfaces/application/push/RequestLifecycleListener.java
branches/RF-7817/core/api/src/main/java/org/richfaces/application/push/TopicKey.java
Log:
https://jira.jboss.org/browse/RF-7817
Modified: branches/RF-7817/core/api/src/main/java/org/richfaces/application/push/Message.java
===================================================================
--- branches/RF-7817/core/api/src/main/java/org/richfaces/application/push/Message.java 2010-10-15 00:24:16 UTC (rev 19575)
+++ branches/RF-7817/core/api/src/main/java/org/richfaces/application/push/Message.java 2010-10-15 00:26:15 UTC (rev 19576)
@@ -21,6 +21,7 @@
*/
package org.richfaces.application.push;
+import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
@@ -28,8 +29,10 @@
* @author Nick Belaevski
*
*/
-public class Message {
+public class Message implements Serializable {
+ private static final long serialVersionUID = -2241242510684986230L;
+
private final TopicKey topicKey;
private Map<String, Object> attributes = null;
Modified: branches/RF-7817/core/api/src/main/java/org/richfaces/application/push/PublisherContext.java
===================================================================
--- branches/RF-7817/core/api/src/main/java/org/richfaces/application/push/PublisherContext.java 2010-10-15 00:24:16 UTC (rev 19575)
+++ branches/RF-7817/core/api/src/main/java/org/richfaces/application/push/PublisherContext.java 2010-10-15 00:26:15 UTC (rev 19576)
@@ -29,13 +29,11 @@
*/
public interface PublisherContext {
+ public static final String ATTRIBUTE_NAME = "__publisherContxt";
+
//TODO - return Future?
//TODO - use topic key?
- public void publish(TopicKey topic, Object data);
-
- //TODO - return Future?
- //TODO - use topic key?
//TODO - priority?
- public void publish(Message message);
+ public void publish(TopicKey topicKey, Object data);
}
Modified: branches/RF-7817/core/api/src/main/java/org/richfaces/application/push/Request.java
===================================================================
--- branches/RF-7817/core/api/src/main/java/org/richfaces/application/push/Request.java 2010-10-15 00:24:16 UTC (rev 19575)
+++ branches/RF-7817/core/api/src/main/java/org/richfaces/application/push/Request.java 2010-10-15 00:26:15 UTC (rev 19576)
@@ -32,8 +32,11 @@
//TODO expose request/session/application maps
- public void write(Message message) throws IOException;
+ public void flushMessages() throws IOException;
+ public void postMessage(Message message);
+
+ //TODO suspend with timeout?
public void suspend() throws IOException;
public void resume() throws IOException;
@@ -43,5 +46,9 @@
public void removeListener(RequestLifecycleListener listener);
public boolean isSuspended();
+
+ public boolean isPolling();
+ public Session getSession();
+
}
Modified: branches/RF-7817/core/api/src/main/java/org/richfaces/application/push/RequestLifecycleListener.java
===================================================================
--- branches/RF-7817/core/api/src/main/java/org/richfaces/application/push/RequestLifecycleListener.java 2010-10-15 00:24:16 UTC (rev 19575)
+++ branches/RF-7817/core/api/src/main/java/org/richfaces/application/push/RequestLifecycleListener.java 2010-10-15 00:26:15 UTC (rev 19576)
@@ -28,6 +28,8 @@
*/
public interface RequestLifecycleListener {
+ public void onFlush(Request request);
+
public void onSuspend(Request request);
public void onDisconnect(Request request);
Modified: branches/RF-7817/core/api/src/main/java/org/richfaces/application/push/TopicKey.java
===================================================================
--- branches/RF-7817/core/api/src/main/java/org/richfaces/application/push/TopicKey.java 2010-10-15 00:24:16 UTC (rev 19575)
+++ branches/RF-7817/core/api/src/main/java/org/richfaces/application/push/TopicKey.java 2010-10-15 00:26:15 UTC (rev 19576)
@@ -21,12 +21,18 @@
*/
package org.richfaces.application.push;
+import java.io.Serializable;
+
/**
* @author Nick Belaevski
*
*/
-public class TopicKey {
+public class TopicKey implements Serializable {
+ /**
+ *
+ */
+ private static final long serialVersionUID = -6967010810728932698L;
private final String topicName;
public TopicKey(String topicName) {
13 years, 8 months