Author: nbelaevski
Date: 2008-03-14 16:31:21 -0400 (Fri, 14 Mar 2008)
New Revision: 6838
Added:
trunk/ui/datascroller/src/main/resources/org/richfaces/renderkit/html/scripts/
trunk/ui/datascroller/src/main/resources/org/richfaces/renderkit/html/scripts/datascroller.js
Modified:
trunk/ui/datascroller/src/main/java/org/richfaces/component/UIDatascroller.java
trunk/ui/datascroller/src/main/java/org/richfaces/renderkit/html/DataScrollerRenderer.java
trunk/ui/datascroller/src/main/templates/org/richfaces/htmlDatascroller.jspx
Log:
http://jira.jboss.com/jira/browse/RF-2182
Modified: trunk/ui/datascroller/src/main/java/org/richfaces/component/UIDatascroller.java
===================================================================
---
trunk/ui/datascroller/src/main/java/org/richfaces/component/UIDatascroller.java 2008-03-14
20:24:23 UTC (rev 6837)
+++
trunk/ui/datascroller/src/main/java/org/richfaces/component/UIDatascroller.java 2008-03-14
20:31:21 UTC (rev 6838)
@@ -426,12 +426,10 @@
if (pageIndex < 1) {
pageIndex = 1;
-
- this.updateModel(pageIndex);
+ setPage(pageIndex);
} else if (pageIndex > pageCount) {
pageIndex = pageCount;
-
- this.updateModel(pageIndex);
+ setPage(pageIndex);
}
currentPageIndex = pageIndex;
Modified:
trunk/ui/datascroller/src/main/java/org/richfaces/renderkit/html/DataScrollerRenderer.java
===================================================================
---
trunk/ui/datascroller/src/main/java/org/richfaces/renderkit/html/DataScrollerRenderer.java 2008-03-14
20:24:23 UTC (rev 6837)
+++
trunk/ui/datascroller/src/main/java/org/richfaces/renderkit/html/DataScrollerRenderer.java 2008-03-14
20:31:21 UTC (rev 6838)
@@ -35,6 +35,7 @@
import javax.faces.event.PhaseId;
import org.ajax4jsf.javascript.JSFunction;
+import org.ajax4jsf.javascript.JSFunctionDefinition;
import org.ajax4jsf.renderkit.AjaxRendererUtils;
import org.ajax4jsf.renderkit.HeaderResourcesRendererBase;
import org.richfaces.component.UIDatascroller;
@@ -48,8 +49,9 @@
}
public void doDecode(FacesContext context, UIComponent component) {
- String param = (String) getParamMap(context).get(
- component.getClientId(context));
+ Map paramMap = getParamMap(context);
+ String clientId = component.getClientId(context);
+ String param = (String) paramMap.get(clientId);
if (param != null) {
UIDatascroller scroller = (UIDatascroller) component;
UIData data = scroller.getDataTable();
@@ -58,9 +60,10 @@
if (pageCount > 1) {
int pageIndex = scroller.getPageIndex(data, pageCount);
int newPage = scroller.getPageForFacet(param, pageIndex, pageCount);
- if (newPage > 0) {
+ int page = scroller.getPage();
+ if (newPage > 0 && newPage != page) {
DataScrollerEvent event = new DataScrollerEvent(scroller,
- String.valueOf(pageIndex), param, newPage);
+ String.valueOf(page), param, newPage);
if (scroller.isImmediate()) {
event.setPhaseId(PhaseId.APPLY_REQUEST_VALUES);
} else {
@@ -216,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);
@@ -227,6 +229,10 @@
}
+ public Object getOnClick(String string) {
+ return "RichFaces.Datascroller.switchToPage(this, event, '" + string +
"');";
+ }
+
public void renderPages(FacesContext context, UIComponent component, int pageIndex,
int count)
throws IOException {
UIDatascroller scroller = (UIDatascroller) component;
@@ -274,16 +280,16 @@
return parameters;
}
- public String getOnClick(FacesContext context, UIComponent component,
- String value) {
+ public String getSubmitFunction(FacesContext context, UIComponent component) {
- JSFunction function = AjaxRendererUtils.buildAjaxFunction(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()){
@@ -294,8 +300,8 @@
StringBuffer buffer = new StringBuffer();
function.appendScript(buffer);
buffer.append("; return false;");
- String script = buffer.toString();
- return script;
+ definition.addToBody(buffer.toString());
+ return definition.toScript();
}
Added:
trunk/ui/datascroller/src/main/resources/org/richfaces/renderkit/html/scripts/datascroller.js
===================================================================
---
trunk/ui/datascroller/src/main/resources/org/richfaces/renderkit/html/scripts/datascroller.js
(rev 0)
+++
trunk/ui/datascroller/src/main/resources/org/richfaces/renderkit/html/scripts/datascroller.js 2008-03-14
20:31:21 UTC (rev 6838)
@@ -0,0 +1,37 @@
+if (!window.RichFaces) {
+ window.RichFaces = {};
+}
+
+RichFaces.Datascroller = {};
+
+RichFaces.Datascroller.COMPONENT = "rich:datascroller";
+
+RichFaces.Datascroller.initialize = function(id, submitFunction) {
+ var scroller = $(id);
+ scroller.richfacesComponent = RichFaces.Datascroller.COMPONENT;
+ scroller.submitFunction = submitFunction;
+};
+
+RichFaces.Datascroller.switchToPage = function(elt, event, newPage) {
+ var e = elt;
+ while (!e.richfacesComponent || e.richfacesComponent !=
RichFaces.Datascroller.COMPONENT) {
+ e = e.parentNode;
+ }
+
+ var id = e.id;
+ var inputId = id + "PageIndex";
+
+ var input = e.lastChild;
+ while (!input.id || input.id != inputId) {
+ input = input.previousSibling;
+ }
+
+ var value = input.value;
+
+ input.value = newPage;
+ try {
+ e.submitFunction(event);
+ } finally {
+ input.value = value;
+ }
+};
\ No newline at end of file
Modified: trunk/ui/datascroller/src/main/templates/org/richfaces/htmlDatascroller.jspx
===================================================================
---
trunk/ui/datascroller/src/main/templates/org/richfaces/htmlDatascroller.jspx 2008-03-14
20:24:23 UTC (rev 6837)
+++
trunk/ui/datascroller/src/main/templates/org/richfaces/htmlDatascroller.jspx 2008-03-14
20:31:21 UTC (rev 6838)
@@ -14,6 +14,7 @@
<h:scripts>
new org.ajax4jsf.javascript.PrototypeScript(),
new org.ajax4jsf.javascript.AjaxScript(),
+ /org/richfaces/renderkit/html/scripts/datascroller.js
</h:scripts>
<f:clientid var="clientId"/>
@@ -22,6 +23,7 @@
</jsp:scriptlet>
<c:object var="singlePageRenderStyle" type="java.lang.String"
/>
+ <c:object var="pageIndex" type="int" />
<jsp:scriptlet>
<![CDATA[
@@ -33,7 +35,7 @@
}
int pageCount = component.getCurrentPageCount(dataTable);
- int pageIndex = component.getCurrentPageIndex(dataTable);
+ pageIndex = component.getCurrentPageIndex(dataTable);
boolean singlePageRender = true;
@@ -66,7 +68,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{
@@ -112,7 +114,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{
@@ -159,7 +161,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{
@@ -212,7 +214,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;
@@ -258,7 +260,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;
@@ -306,7 +308,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;
@@ -351,5 +353,9 @@
}
]]>
</jsp:scriptlet>
+ <script type="text/javascript">
+ RichFaces.Datascroller.initialize('#{clientId}',
#{this:getSubmitFunction(context,component)});
+ </script>
+ <input type="hidden" name="#{clientId}"
id="#{clientId}PageIndex" value="#{pageIndex}" />
</div>
</f:root>
\ No newline at end of file