Author: nbelaevski
Date: 2008-04-10 13:54:32 -0400 (Thu, 10 Apr 2008)
New Revision: 7743
Added:
branches/3.1.x/framework/api/src/main/java/org/ajax4jsf/javascript/JSLiteral.java
Modified:
branches/3.1.x/samples/datascroller-sample/src/main/webapp/pages/index.jsp
branches/3.1.x/ui/datascroller/src/main/config/component/datascroller.xml
branches/3.1.x/ui/datascroller/src/main/java/org/richfaces/renderkit/html/DataScrollerRenderer.java
branches/3.1.x/ui/datascroller/src/main/templates/org/richfaces/htmlDatascroller.jspx
Log:
http://jira.jboss.com/jira/browse/RF-2714
http://jira.jboss.com/jira/browse/RF-2233
Added: branches/3.1.x/framework/api/src/main/java/org/ajax4jsf/javascript/JSLiteral.java
===================================================================
--- branches/3.1.x/framework/api/src/main/java/org/ajax4jsf/javascript/JSLiteral.java
(rev 0)
+++
branches/3.1.x/framework/api/src/main/java/org/ajax4jsf/javascript/JSLiteral.java 2008-04-10
17:54:32 UTC (rev 7743)
@@ -0,0 +1,58 @@
+/*
+ * JSLiteral.java Date created: 29.01.2008
+ * Last modified by: $Author$
+ * $Revision$ $Date$
+ */
+
+package org.ajax4jsf.javascript;
+
+/**
+ * Class provides creation of simple literal javascript to be set in ajax response data
+ * @author Andrey Markavtsov
+ *
+ */
+public class JSLiteral extends ScriptStringBase {
+
+ /** Javascript literal text */
+ private String literal;
+
+
+ /**
+ * Default constructor
+ */
+ public JSLiteral() {
+ super();
+ }
+
+ /**
+ * Constructor using literal parameter
+ * @param literal
+ */
+ public JSLiteral(String literal) {
+ super();
+ this.literal = literal;
+ }
+
+ /* (non-Javadoc)
+ * @see org.ajax4jsf.javascript.ScriptString#appendScript(java.lang.StringBuffer)
+ */
+ public void appendScript(StringBuffer jsString) {
+ jsString.append(literal);
+
+ }
+
+ /**
+ * @return the literal
+ */
+ public String getLiteral() {
+ return literal;
+ }
+
+ /**
+ * @param literal the literal to set
+ */
+ public void setLiteral(String literal) {
+ this.literal = literal;
+ }
+
+}
Modified: branches/3.1.x/samples/datascroller-sample/src/main/webapp/pages/index.jsp
===================================================================
--- branches/3.1.x/samples/datascroller-sample/src/main/webapp/pages/index.jsp 2008-04-10
16:39:51 UTC (rev 7742)
+++ branches/3.1.x/samples/datascroller-sample/src/main/webapp/pages/index.jsp 2008-04-10
17:54:32 UTC (rev 7743)
@@ -23,9 +23,6 @@
<h:outputText value="Data Table test" />
<br />
-
-
-
<h:dataTable rows="#{testBean.rows}" id="master"
border="1" value="#{testBean.data}" var="data">
<f:facet name="header">
<h:outputText value="My table" />
@@ -58,7 +55,7 @@
</f:facet>
</h:column>
<f:facet name="footer">
- <ds:datascroller for="master" reRender="actionCount, eventCount"
rendered="true" fastStep="2"
actionListener="#{testBean.onAction}"
renderIfSinglePage="#{testBean.renderIfSinglePage}"
scrollerListener="#{testBean.doScroll}"
maxPages="#{testBean.maxpage}"/>
+ <ds:datascroller for="master" reRender="actionCount, eventCount"
rendered="true" fastStep="2"
actionListener="#{testBean.onAction}"
renderIfSinglePage="#{testBean.renderIfSinglePage}"
scrollerListener="#{testBean.doScroll}" maxPages="#{testBean.maxpage}"
onpagechange="return confirm('Do you want to go to: ' + event.memo.page +
'?')" />
</f:facet>
</h:dataTable>
Modified: branches/3.1.x/ui/datascroller/src/main/config/component/datascroller.xml
===================================================================
--- branches/3.1.x/ui/datascroller/src/main/config/component/datascroller.xml 2008-04-10
16:39:51 UTC (rev 7742)
+++ branches/3.1.x/ui/datascroller/src/main/config/component/datascroller.xml 2008-04-10
17:54:32 UTC (rev 7743)
@@ -284,6 +284,10 @@
<description>Name of variable in request scope containing number of
pages</description>
</property>
+ <property>
+ <name>onpagechange</name>
+ <classname>java.lang.String</classname>
+ </property>
</component>
&listeners;
</components>
Modified:
branches/3.1.x/ui/datascroller/src/main/java/org/richfaces/renderkit/html/DataScrollerRenderer.java
===================================================================
---
branches/3.1.x/ui/datascroller/src/main/java/org/richfaces/renderkit/html/DataScrollerRenderer.java 2008-04-10
16:39:51 UTC (rev 7742)
+++
branches/3.1.x/ui/datascroller/src/main/java/org/richfaces/renderkit/html/DataScrollerRenderer.java 2008-04-10
17:54:32 UTC (rev 7743)
@@ -36,6 +36,8 @@
import org.ajax4jsf.Messages;
import org.ajax4jsf.javascript.JSFunction;
+import org.ajax4jsf.javascript.JSFunctionDefinition;
+import org.ajax4jsf.javascript.JSLiteral;
import org.ajax4jsf.renderkit.AjaxRendererUtils;
import org.ajax4jsf.renderkit.HeaderResourcesRendererBase;
import org.richfaces.component.UIDatascroller;
@@ -217,8 +219,7 @@
} else {
out.writeAttribute("class", "dr-dscr-inact
rich-datascr-inact "+
styleClass, null);
- out.writeAttribute("onclick", getOnClick(context, component,
- Integer.toString(i + 1)), null);
+ out.writeAttribute("onclick", getOnClick(Integer.toString(i +
1)), null);
}
if (null != style) out.writeAttribute("style", style, null);
out.writeText(Integer.toString(i + 1), null);
@@ -228,6 +229,10 @@
}
+ public Object getOnClick(String string) {
+ return "Event.fire(this, 'rich:datascroller:onscroll', {'page':
'" + string + "'});";
+ }
+
public void renderPages(FacesContext context, UIComponent component, UIData data)
throws IOException {
UIDatascroller scroller = (UIDatascroller) component;
@@ -275,28 +280,44 @@
return parameters;
}
- public String getOnClick(FacesContext context, UIComponent component,
- String value) {
-
- JSFunction function = AjaxRendererUtils.buildAjaxFunction(component,
+ public String getSubmitFunction(FacesContext context, UIComponent component) {
+ JSFunctionDefinition definition = new JSFunctionDefinition("event");
+
+ JSFunction function = AjaxRendererUtils.buildAjaxFunction(component,
context);
UIDatascroller scroller = (UIDatascroller) component;
Map eventOptions = AjaxRendererUtils.buildEventOptions(context,
component);
Map parameters = (Map) eventOptions.get("parameters");
- parameters.put(scroller.getClientId(context), value);
Map params = getParameters(context,component);
if(!params.isEmpty()){
parameters.putAll(params);
}
+ parameters.put(component.getClientId(context), new
JSLiteral("event.memo.page"));
+
function.addParameter(eventOptions);
StringBuffer buffer = new StringBuffer();
function.appendScript(buffer);
buffer.append("; return false;");
- String script = buffer.toString();
- return script;
+
+ String onPageChange = (String)
component.getAttributes().get("onpagechange");
+ if (onPageChange != null && onPageChange.length() != 0) {
+ JSFunctionDefinition onPageChangeDef = new JSFunctionDefinition("event");
+ onPageChangeDef.addToBody(onPageChange);
+ onPageChangeDef.addToBody("; return true;");
+
+ definition.addToBody("if (");
+ definition.addToBody(onPageChangeDef.toScript());
+ definition.addToBody("(event)) {");
+ definition.addToBody(buffer.toString());
+ definition.addToBody("}");
+ } else {
+ definition.addToBody(buffer.toString());
+ }
+
+ return definition.toScript();
}
Modified:
branches/3.1.x/ui/datascroller/src/main/templates/org/richfaces/htmlDatascroller.jspx
===================================================================
---
branches/3.1.x/ui/datascroller/src/main/templates/org/richfaces/htmlDatascroller.jspx 2008-04-10
16:39:51 UTC (rev 7742)
+++
branches/3.1.x/ui/datascroller/src/main/templates/org/richfaces/htmlDatascroller.jspx 2008-04-10
17:54:32 UTC (rev 7743)
@@ -13,7 +13,7 @@
<h:scripts>
new org.ajax4jsf.javascript.PrototypeScript(),
- new org.ajax4jsf.javascript.AjaxScript(),
+ new org.ajax4jsf.javascript.AjaxScript()
</h:scripts>
<f:clientid var="clientId"/>
@@ -57,7 +57,7 @@
if (controlsState.isFirstRendered()){
if (controlsState.isFirstEnabled()){
variables.setVariable("buttonClass", "");
- variables.setVariable("onclick",
getOnClick(context,component,component.FIRST_FACET_NAME));
+ variables.setVariable("onclick",
getOnClick(component.FIRST_FACET_NAME));
variables.setVariable("facet", component.FIRST_FACET_NAME);
facet=component.FIRST_FACET_NAME;
}else{
@@ -103,7 +103,7 @@
if (controlsState.isFastRewindRendered()){
if (controlsState.isFastRewindEnabled()){
variables.setVariable("buttonClass", "");
- variables.setVariable("onclick",
getOnClick(context,component,component.FAST_REWIND_FACET_NAME));
+ variables.setVariable("onclick",
getOnClick(component.FAST_REWIND_FACET_NAME));
variables.setVariable("facet",
component.FAST_REWIND_FACET_NAME);
facet=component.FAST_REWIND_FACET_NAME;
}else{
@@ -150,7 +150,7 @@
if (controlsState.isPreviousRendered()){
if (controlsState.isPreviousEnabled()){
variables.setVariable("buttonClass", "");
- variables.setVariable("onclick",
getOnClick(context,component,component.PREVIOUS_FACET_NAME));
+ variables.setVariable("onclick",
getOnClick(component.PREVIOUS_FACET_NAME));
variables.setVariable("facet",
component.PREVIOUS_FACET_NAME);
facet=component.PREVIOUS_FACET_NAME;
}else{
@@ -203,7 +203,7 @@
<jsp:scriptlet><![CDATA[
if (controlsState.isNextRendered()){
if (controlsState.isNextEnabled()){
- variables.setVariable("onclick",
getOnClick(context,component,component.NEXT_FACET_NAME));
+ variables.setVariable("onclick",
getOnClick(component.NEXT_FACET_NAME));
variables.setVariable("buttonClass", "");
variables.setVariable("facet", component.NEXT_FACET_NAME);
facet=component.NEXT_FACET_NAME;
@@ -249,7 +249,7 @@
<jsp:scriptlet><![CDATA[
if (controlsState.isFastForwardRendered()){
if (controlsState.isFastForwardEnabled()){
- variables.setVariable("onclick",
getOnClick(context,component,component.FAST_FORWARD_FACET_NAME));
+ variables.setVariable("onclick",
getOnClick(component.FAST_FORWARD_FACET_NAME));
variables.setVariable("buttonClass", "");
variables.setVariable("facet",
component.FAST_FORWARD_FACET_NAME);
facet=component.FAST_FORWARD_FACET_NAME;
@@ -297,7 +297,7 @@
<jsp:scriptlet><![CDATA[
if (controlsState.isLastRendered()){
if (controlsState.isLastEnabled()){
- variables.setVariable("onclick",
getOnClick(context,component,component.LAST_FACET_NAME));
+ variables.setVariable("onclick",
getOnClick(component.LAST_FACET_NAME));
variables.setVariable("buttonClass", "");
variables.setVariable("facet", component.LAST_FACET_NAME);
facet=component.LAST_FACET_NAME;
@@ -342,5 +342,8 @@
}
]]>
</jsp:scriptlet>
+ <script type="text/javascript">
+ Event.observe('#{clientId}', 'rich:datascroller:onscroll',
#{this:getSubmitFunction(context,component)});
+ </script>
</div>
</f:root>
\ No newline at end of file