Author: A.Skokov
Date: 2007-07-06 08:08:29 -0400 (Fri, 06 Jul 2007)
New Revision: 1515
Modified:
branches/3.0.2/richfaces/datascroller/src/main/java/org/richfaces/component/UIDatascroller.java
branches/3.0.2/richfaces/datascroller/src/main/java/org/richfaces/event/DataScrollerEvent.java
branches/3.0.2/richfaces/datascroller/src/main/java/org/richfaces/renderkit/html/DataScrollerRenderer.java
Log:
http://jira.jboss.com/jira/browse/RF-409
Modified:
branches/3.0.2/richfaces/datascroller/src/main/java/org/richfaces/component/UIDatascroller.java
===================================================================
---
branches/3.0.2/richfaces/datascroller/src/main/java/org/richfaces/component/UIDatascroller.java 2007-07-06
12:02:04 UTC (rev 1514)
+++
branches/3.0.2/richfaces/datascroller/src/main/java/org/richfaces/component/UIDatascroller.java 2007-07-06
12:08:29 UTC (rev 1515)
@@ -21,9 +21,14 @@
package org.richfaces.component;
+import org.ajax4jsf.framework.ajax.AjaxActionComponent;
+import org.ajax4jsf.framework.renderer.AjaxRendererUtils;
+import org.richfaces.event.DataScrollerEvent;
+import org.richfaces.event.DataScrollerListener;
+import org.richfaces.event.DataScrollerSource;
+
import javax.faces.FacesException;
import javax.faces.component.ActionSource;
-import javax.faces.component.UICommand;
import javax.faces.component.UIComponent;
import javax.faces.component.UIData;
import javax.faces.context.FacesContext;
@@ -31,19 +36,13 @@
import javax.faces.event.AbortProcessingException;
import javax.faces.event.FacesEvent;
-import org.ajax4jsf.framework.renderer.AjaxRendererUtils;
-import org.richfaces.event.DataScrollerEvent;
-import org.richfaces.event.DataScrollerListener;
-import org.richfaces.event.DataScrollerSource;
-
-/**
- * JSF component class
- */
+/** JSF component class */
//xxxx nick -> alex - extend UIComponentBase and
//create event listener & event classes to define PageSwitchEvent
//public abstract class UIDatascroller extends UIComponentBase implements
DataScrollerSource{
-public abstract class UIDatascroller extends UICommand implements
DataScrollerSource,ActionSource{
+public abstract class UIDatascroller extends AjaxActionComponent
+ implements DataScrollerSource, ActionSource {
public static final String COMPONENT_TYPE = "org.richfaces.Datascroller";
public static final String COMPONENT_FAMILY =
"org.richfaces.Datascroller";
@@ -67,18 +66,22 @@
public static final String NEXT_DISABLED_FACET_NAME = "next_disabled";
- public static final String PREVIOUS_DISABLED_FACET_NAME =
"previous_disabled";
+ public static final String PREVIOUS_DISABLED_FACET_NAME
+ = "previous_disabled";
- public static final String FAST_FORWARD_DISABLED_FACET_NAME =
"fastforward_disabled";
+ public static final String FAST_FORWARD_DISABLED_FACET_NAME
+ = "fastforward_disabled";
- public static final String FAST_REWIND_DISABLED_FACET_NAME =
"fastrewind_disabled";
-
+ public static final String FAST_REWIND_DISABLED_FACET_NAME
+ = "fastrewind_disabled";
+
public void addScrollerListener(DataScrollerListener listener) {
addFacesListener(listener);
}
public DataScrollerListener[] getScrollerListeners() {
- return (DataScrollerListener[]) getFacesListeners(DataScrollerListener.class);
+ return (DataScrollerListener[]) getFacesListeners(
+ DataScrollerListener.class);
}
public void removeScrollerListener(DataScrollerListener listener) {
@@ -88,16 +91,18 @@
public void broadcast(FacesEvent event) throws AbortProcessingException {
super.broadcast(event);
if (event instanceof DataScrollerEvent) {
- DataScrollerEvent dataScrollerEvent = (DataScrollerEvent) event;
- setPage(dataScrollerEvent.getNewScrolVal());
+ DataScrollerEvent dataScrollerEvent = (DataScrollerEvent) event;
+ setPage(dataScrollerEvent.getNewScrolVal());
- FacesContext context = FacesContext.getCurrentInstance();
+ FacesContext context = FacesContext.getCurrentInstance();
AjaxRendererUtils.addRegionByName(context, this, this.getId());
AjaxRendererUtils.addRegionByName(context, this, this.getFor());
-
+
+ setupReRender(context);
+
MethodBinding scrollerListener = getScrollerListener();
if (scrollerListener != null) {
- scrollerListener.invoke(context, new Object[] {event});
+ scrollerListener.invoke(context, new Object[]{event});
}
}
}
@@ -153,20 +158,23 @@
public abstract void setStyleClass(String styleClass);
public abstract void setStyle(String styleClass);
-
+
public abstract String getAlign();
public abstract void setAlign(String align);
-
+
public abstract String getBoundaryControls();
+
public abstract void setBoundaryControls(String boundaryControls);
public abstract String getFastControls();
+
public abstract void setFastControls(String fastControls);
public abstract String getStepControls();
+
public abstract void setStepControls(String stepControls);
-
+
/**
* Finds the dataTable which id is mapped to the "for" property
*
@@ -183,16 +191,19 @@
return (UIData) forComp;
}
}
- throw new FacesException("could not dataTable for datascroller " +
this.getId());
+ throw new FacesException(
+ "could not dataTable for datascroller " + this.getId());
} else {
forComp = findComponent(forAttribute);
}
if (forComp == null) {
throw new IllegalArgumentException("could not dataTable with id
'"
- + forAttribute + "'");
+ + forAttribute + "'");
} else if (!(forComp instanceof UIData)) {
- throw new IllegalArgumentException("component with id '" +
forAttribute
- + "' must be of type " + UIData.class.getName() +
", not type "
+ throw new IllegalArgumentException(
+ "component with id '" + forAttribute
+ + "' must be of type " + UIData.class.getName()
+ + ", not type "
+ forComp.getClass().getName());
}
return (UIData) forComp;
@@ -203,7 +214,7 @@
int rows = getRows(uiData);
if (0 == rows) {
throw new FacesException("Missing 'rows' attribute on component
'"
- + uiData.getId() + "'");
+ + uiData.getId() + "'");
}
int pageIndex;
@@ -219,7 +230,7 @@
}
return pageIndex;
}
-
+
/**
* Gets the index of the current page
*
@@ -234,7 +245,8 @@
* Sets the page number according to the parameter recived from the
* commandLink
*
- * @param facetName - can be "first:, "last", "next",
"previous", "fastforward", "fastrewind"
+ * @param facetName - can be "first:, "last", "next",
"previous",
+ * "fastforward", "fastrewind"
*/
public void setPage(String facetName) {
@@ -246,11 +258,15 @@
dataTable.setFirst(0);
} else if (PREVIOUS_FACET_NAME.equals(facetName)) {
int previous = dataTable.getFirst() - getRows(dataTable);
- if (previous >= 0) setFirstRow(previous);
+ if (previous >= 0) {
+ setFirstRow(previous);
+ }
} else if (NEXT_FACET_NAME.equals(facetName)) {
int rows = getRows(dataTable);
int next = dataTable.getFirst() + rows;
- if (next < getRowCount(dataTable)) setFirstRow(next);
+ if (next < getRowCount(dataTable)) {
+ setFirstRow(next);
+ }
//if (rows>0){
// if (((next+rows)/rows)>getMaxPages()){
// next=getMaxPages()*rows-rows;;
@@ -259,11 +275,14 @@
} else if (FAST_FORWARD_FACET_NAME.equals(facetName)) {
int fastStep = getFastStep();
int rows = getRows(dataTable);
- if (fastStep <= 0) fastStep = 1;
+ if (fastStep <= 0) {
+ fastStep = 1;
+ }
int next = dataTable.getFirst() + rows * fastStep;
int rowcount = getRowCount(dataTable);
- if (next >= rowcount)
+ if (next >= rowcount) {
next = (rowcount - 1) - ((rowcount - 1) % rows);
+ }
//if (rows>0){
// if (((next+rows)/rows)>getMaxPages()){
// next=getMaxPages()*rows-rows;;
@@ -272,16 +291,20 @@
setFirstRow(next);
} else if (FAST_REWIND_FACET_NAME.equals(facetName)) {
int fastStep = getFastStep();
- if (fastStep <= 0) fastStep = 1;
+ if (fastStep <= 0) {
+ fastStep = 1;
+ }
int previous = dataTable.getFirst() - getRows(dataTable) * fastStep;
- if (previous < 0) previous = 0;
+ if (previous < 0) {
+ previous = 0;
+ }
setFirstRow(previous);
} else if (LAST_FACET_NAME.equals(facetName)) {
int rowcount = getRowCount(dataTable);
int rows = getRows(dataTable);
int delta = rowcount % rows;
int first = delta > 0 && delta < rows ? rowcount - delta :
rowcount
- - rows;
+ - rows;
if (first >= 0) {
//if (rows>0){
//if (((first+rows)/rows)>getMaxPages()){
@@ -311,7 +334,7 @@
int rows = getRows(data);
int pageCount;
if (rows > 0) {
- int rowCount = getRowCount(data);
+ int rowCount = getRowCount(data);
pageCount = rows <= 0 ? 1 : rowCount / rows;
if (rowCount % rows > 0) {
pageCount++;
@@ -325,26 +348,22 @@
}
return pageCount;
}
-
- /**
- * @return the page count of the uidata
- */
+
+ /** @return the page count of the uidata */
public int getPageCount() {
return getPageCount(getDataTable());
}
public int getRowCount(UIData data) {
int rowCount = data.getRowCount();
- if (rowCount >= 0) {
- return rowCount;
+ if (rowCount >= 0) {
+ return rowCount;
}
-
- return BinarySearch.search(data);
+
+ return BinarySearch.search(data);
}
-
- /**
- * @return int
- */
+
+ /** @return int */
public int getRowCount() {
//xxx nick -> alex - scrollable models can return -1 here
//let's implement "dychotomic" discovery
@@ -352,7 +371,7 @@
// setPage() { setRowIndex(pageIdx * rows); }
// isPageAvailable() { return isRowAvailable() }
//return getUIData().getRowCount();
- return getRowCount(getDataTable());
+ return getRowCount(getDataTable());
}
public int getRows(UIData data) {
@@ -364,7 +383,7 @@
return row;
}
-
+
// facet getter methods
public UIComponent getFirst() {
return getFacet(FIRST_FACET_NAME);
@@ -391,11 +410,11 @@
}
public int getFirstRow(UIData data) {
- return data.getFirst();
+ return data.getFirst();
}
-
- public void setFirstRow(int rows) {
- getDataTable().setFirst(rows);
+
+ public void setFirstRow(int rows) {
+ getDataTable().setFirst(rows);
//setControls();
}
@@ -404,10 +423,11 @@
}
static class BinarySearch {
+
public static int search(UIData data) {
- int rowIndex = data.getRowIndex();
+ int rowIndex = data.getRowIndex();
try {
- int n = 1;
+ int n = 1;
int k = 2;
for (; ;) {
data.setRowIndex(k - 1);
Modified:
branches/3.0.2/richfaces/datascroller/src/main/java/org/richfaces/event/DataScrollerEvent.java
===================================================================
---
branches/3.0.2/richfaces/datascroller/src/main/java/org/richfaces/event/DataScrollerEvent.java 2007-07-06
12:02:04 UTC (rev 1514)
+++
branches/3.0.2/richfaces/datascroller/src/main/java/org/richfaces/event/DataScrollerEvent.java 2007-07-06
12:08:29 UTC (rev 1515)
@@ -21,30 +21,30 @@
package org.richfaces.event;
+import org.ajax4jsf.framework.ajax.AjaxActionEvent;
+
import javax.faces.component.UIComponent;
-import javax.faces.event.ActionEvent;
import javax.faces.event.FacesListener;
-/**
- * @author Wesley Hales
- */
-public class DataScrollerEvent extends ActionEvent {
+/** @author Wesley Hales */
+public class DataScrollerEvent extends AjaxActionEvent {
/**
- *
- */
- private static final long serialVersionUID = 2657353903701932561L;
- private String oldScrolVal;
- private String newScrolVal;
+ *
+ */
+ private static final long serialVersionUID = 2657353903701932561L;
+ private String oldScrolVal;
+ private String newScrolVal;
/**
- * Creates a new ScrollerEvent.
- *
- * @param component the source of the event
- * @param thisOldScrolVal the previously showing item identifier
- * @param thisNewScrolVal the currently showing item identifier
- */
- public DataScrollerEvent(UIComponent component, String thisOldScrolVal, String
thisNewScrolVal) {
+ * Creates a new ScrollerEvent.
+ *
+ * @param component the source of the event
+ * @param thisOldScrolVal the previously showing item identifier
+ * @param thisNewScrolVal the currently showing item identifier
+ */
+ public DataScrollerEvent(UIComponent component, String thisOldScrolVal,
+ String thisNewScrolVal) {
super(component);
oldScrolVal = thisOldScrolVal;
newScrolVal = thisNewScrolVal;
@@ -58,23 +58,19 @@
return newScrolVal;
}
- public boolean isAppropriateListener(FacesListener listener){
- return super.isAppropriateListener(listener) || (listener instanceof
DataScrollerListener);
+ public boolean isAppropriateListener(FacesListener listener) {
+ return super.isAppropriateListener(listener)
+ || (listener instanceof DataScrollerListener);
}
/**
- * Delivers this event to the SliderListener.
- *
- * @param listener the slider listener
- */
- public void processListener(FacesListener listener){
- if (listener instanceof DataScrollerListener) {
- DataScrollerListener dataScrollerListener = (DataScrollerListener) listener;
- dataScrollerListener.processScroller(this);
- }
-
+ * Delivers this event to the SliderListener.
+ *
+ * @param listener the slider listener
+ */
+ public void processListener(FacesListener listener) {
if (super.isAppropriateListener(listener)) {
- super.processListener(listener);
+ super.processListener(listener);
}
}
}
Modified:
branches/3.0.2/richfaces/datascroller/src/main/java/org/richfaces/renderkit/html/DataScrollerRenderer.java
===================================================================
---
branches/3.0.2/richfaces/datascroller/src/main/java/org/richfaces/renderkit/html/DataScrollerRenderer.java 2007-07-06
12:02:04 UTC (rev 1514)
+++
branches/3.0.2/richfaces/datascroller/src/main/java/org/richfaces/renderkit/html/DataScrollerRenderer.java 2007-07-06
12:08:29 UTC (rev 1515)
@@ -21,14 +21,6 @@
package org.richfaces.renderkit.html;
-import java.io.IOException;
-import java.util.Map;
-
-import javax.faces.component.UIComponent;
-import javax.faces.component.UIData;
-import javax.faces.context.FacesContext;
-import javax.faces.context.ResponseWriter;
-
import org.ajax4jsf.framework.renderer.AjaxRendererUtils;
import org.ajax4jsf.framework.renderer.ComponentVariables;
import org.ajax4jsf.framework.renderer.ComponentsVariableResolver;
@@ -37,253 +29,284 @@
import org.richfaces.component.UIDatascroller;
import org.richfaces.event.DataScrollerEvent;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIData;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+import javax.faces.event.PhaseId;
+import java.io.IOException;
+import java.util.Map;
+
public class DataScrollerRenderer extends HeaderResourcesRendererBase {
- protected Class getComponentClass() {
- return UIDatascroller.class;
- }
+ protected Class getComponentClass() {
+ return UIDatascroller.class;
+ }
- public void encodeBegin(FacesContext context, UIComponent component)
- throws IOException {
+ public void encodeBegin(FacesContext context, UIComponent component)
+ throws IOException {
- UIDatascroller scroller = (UIDatascroller) component;
+ UIDatascroller scroller = (UIDatascroller) component;
- UIData dataTable = scroller.getDataTable();
+ UIData dataTable = scroller.getDataTable();
- ComponentVariables variables = ComponentsVariableResolver.getVariables(this,
component);
- variables.setVariable("dataTable", dataTable);
- if (!(scroller.getPageCount(dataTable) == 1) || (scroller.isRenderIfSinglePage()))
- {
- variables.setVariable("rendered", Boolean.TRUE);
- super.encodeBegin(context, component);
- }
- }
+ ComponentVariables variables = ComponentsVariableResolver.getVariables(
+ this, component);
+ variables.setVariable("dataTable", dataTable);
+ if (!(scroller.getPageCount(dataTable) == 1)
+ || (scroller.isRenderIfSinglePage())) {
+ variables.setVariable("rendered", Boolean.TRUE);
+ super.encodeBegin(context, component);
+ }
+ }
- public void encodeEnd(FacesContext context, UIComponent component)
- throws IOException {
- ComponentVariables variables = ComponentsVariableResolver.getVariables(this,
component);
+ public void encodeEnd(FacesContext context, UIComponent component)
+ throws IOException {
+ ComponentVariables variables = ComponentsVariableResolver.getVariables(
+ this, component);
- if (Boolean.TRUE.equals(variables.getVariable("rendered")))
- {
- super.encodeEnd(context, component);
- }
- }
+ if (Boolean.TRUE.equals(variables.getVariable("rendered"))) {
+ super.encodeEnd(context, component);
+ }
+ }
- public void decode(FacesContext context, UIComponent component) {
+ public void doDecode(FacesContext context, UIComponent component) {
- String param = (String) getParamMap(context).get(
- component.getClientId(context));
- UIDatascroller scroller = (UIDatascroller) component;
+ String param = (String) getParamMap(context).get(
+ component.getClientId(context));
+ UIDatascroller scroller = (UIDatascroller) component;
- if (param != null) {
- new DataScrollerEvent(scroller, String.valueOf(scroller.getPageIndex()),
param).queue();
- }
- }
+ if (param != null) {
+ DataScrollerEvent event = new DataScrollerEvent(scroller,
+ String.valueOf(scroller.getPageIndex()), param);
+ if (scroller.isImmediate()) {
+ event.setPhaseId(PhaseId.APPLY_REQUEST_VALUES);
+ } else {
+ event.setPhaseId(PhaseId.INVOKE_APPLICATION);
+ }
- public ControlsState getControlsState(FacesContext context, UIDatascroller datascroller,
UIData dataTable) {
- int pageIndex = datascroller.getPageIndex(dataTable);
- int pageCount = datascroller.getPageCount(dataTable);
- int minPageIdx = 1;
- int maxPageIdx = pageCount;
- int fastStep = datascroller.getFastStep();
- if (fastStep <= 1) {
- fastStep = 1;
- }
+ component.queueEvent(event);
+ }
+ }
- boolean useFirst = true;
- boolean useLast = true;
+ public ControlsState getControlsState(FacesContext context,
+ UIDatascroller datascroller, UIData dataTable) {
+ int pageIndex = datascroller.getPageIndex(dataTable);
+ int pageCount = datascroller.getPageCount(dataTable);
+ int minPageIdx = 1;
+ int maxPageIdx = pageCount;
+ int fastStep = datascroller.getFastStep();
+ if (fastStep <= 1) {
+ fastStep = 1;
+ }
- boolean useBackFast = true;
- boolean useForwFast = true;
+ boolean useFirst = true;
+ boolean useLast = true;
- ControlsState controlsState = new ControlsState();
-
- if (pageIndex <= minPageIdx) {
- useFirst = false;
- }
+ boolean useBackFast = true;
+ boolean useForwFast = true;
- if (pageIndex >= maxPageIdx) {
- useLast = false;
- }
+ ControlsState controlsState = new ControlsState();
- if (pageIndex - fastStep < minPageIdx) {
- useBackFast = false;
- }
+ if (pageIndex <= minPageIdx) {
+ useFirst = false;
+ }
- if (pageIndex + fastStep > maxPageIdx) {
- useForwFast = false;
- }
+ if (pageIndex >= maxPageIdx) {
+ useLast = false;
+ }
- boolean isAuto;
- String boundaryControls = datascroller.getBoundaryControls();
- String stepControls = datascroller.getStepControls();
- String fastControls = datascroller.getFastControls();
-
- if ((isAuto = "auto".equals(boundaryControls)) ||
"show".equals(boundaryControls)) {
- if (isAuto) {
- controlsState.setFirstRendered(useFirst);
- controlsState.setLastRendered(useLast);
- }
+ if (pageIndex - fastStep < minPageIdx) {
+ useBackFast = false;
+ }
- controlsState.setFirstEnabled(useFirst);
- controlsState.setLastEnabled(useLast);
- } else {
- controlsState.setFirstRendered(false);
- controlsState.setLastRendered(false);
- }
+ if (pageIndex + fastStep > maxPageIdx) {
+ useForwFast = false;
+ }
- if ((isAuto = "auto".equals(stepControls)) ||
"show".equals(stepControls)) {
- if (isAuto) {
- controlsState.setPreviousRendered(useFirst);
- controlsState.setNextRendered(useLast);
- }
+ boolean isAuto;
+ String boundaryControls = datascroller.getBoundaryControls();
+ String stepControls = datascroller.getStepControls();
+ String fastControls = datascroller.getFastControls();
- controlsState.setPreviousEnabled(useFirst);
- controlsState.setNextEnabled(useLast);
- } else {
- controlsState.setPreviousRendered(false);
- controlsState.setNextRendered(false);
- }
+ if ((isAuto = "auto".equals(boundaryControls)) ||
"show".equals(
+ boundaryControls)) {
+ if (isAuto) {
+ controlsState.setFirstRendered(useFirst);
+ controlsState.setLastRendered(useLast);
+ }
- if ((isAuto = "auto".equals(fastControls)) ||
"show".equals(fastControls)) {
- if (isAuto) {
- controlsState.setFastForwardRendered(useForwFast);
- controlsState.setFastRewindRendered(useBackFast);
- }
+ controlsState.setFirstEnabled(useFirst);
+ controlsState.setLastEnabled(useLast);
+ } else {
+ controlsState.setFirstRendered(false);
+ controlsState.setLastRendered(false);
+ }
- controlsState.setFastForwardEnabled(useForwFast);
- controlsState.setFastRewindEnabled(useBackFast);
- } else {
- controlsState.setFastForwardRendered(false);
- controlsState.setFastRewindRendered(false);
- }
-
- return controlsState;
- }
+ if ((isAuto = "auto".equals(stepControls)) || "show".equals(
+ stepControls)) {
+ if (isAuto) {
+ controlsState.setPreviousRendered(useFirst);
+ controlsState.setNextRendered(useLast);
+ }
- public void renderPager(FacesContext context, UIComponent component) throws IOException
{
- ComponentVariables variables = ComponentsVariableResolver.getVariables(this,
component);
- UIData data = (UIData) variables.getVariable("dataTable");
+ controlsState.setPreviousEnabled(useFirst);
+ controlsState.setNextEnabled(useLast);
+ } else {
+ controlsState.setPreviousRendered(false);
+ controlsState.setNextRendered(false);
+ }
- ResponseWriter out = context.getResponseWriter();
- UIDatascroller scroller = (UIDatascroller) component;
- int currentPage = scroller.getPageIndex(data);
+ if ((isAuto = "auto".equals(fastControls)) || "show".equals(
+ fastControls)) {
+ if (isAuto) {
+ controlsState.setFastForwardRendered(useForwFast);
+ controlsState.setFastRewindRendered(useBackFast);
+ }
- int maxPages = scroller.getMaxPages();
- if (maxPages <= 1) {
- maxPages = 1;
- }
- int pageCount = scroller.getPageCount(data);
- if (pageCount <= 1) {
- return;
- }
+ controlsState.setFastForwardEnabled(useForwFast);
+ controlsState.setFastRewindEnabled(useBackFast);
+ } else {
+ controlsState.setFastForwardRendered(false);
+ controlsState.setFastRewindRendered(false);
+ }
- int delta = maxPages / 2;
+ return controlsState;
+ }
- int pages;
- int start;
- if (pageCount > maxPages && currentPage > delta) {
- pages = maxPages;
- start = currentPage - pages / 2 - 1;
- if (start + pages > pageCount) {
- start = pageCount - pages;
- }
- } else {
- pages = pageCount < maxPages ? pageCount : maxPages;
- start = 0;
- }
+ public void renderPager(FacesContext context, UIComponent component)
+ throws IOException {
+ ComponentVariables variables = ComponentsVariableResolver.getVariables(
+ this, component);
+ UIData data = (UIData) variables.getVariable("dataTable");
- for (int i = start, size = start + pages; i < size; i++) {
- //String styleClass;
- //String style;
+ ResponseWriter out = context.getResponseWriter();
+ UIDatascroller scroller = (UIDatascroller) component;
+ int currentPage = scroller.getPageIndex(data);
- boolean isCurrentPage = (i + 1 == currentPage);
- /*
- if (isCurrentPage) {
- styleClass = scroller.getSelectedStyleClass();
- style = scroller.getSelectedStyle();
- }
- else {
- styleClass = scroller.getStyleClass();
- style = scroller.getStyle();
- }
+ int maxPages = scroller.getMaxPages();
+ if (maxPages <= 1) {
+ maxPages = 1;
+ }
+ int pageCount = scroller.getPageCount(data);
+ if (pageCount <= 1) {
+ return;
+ }
- if (style==null){
- style="";
- }
- if (styleClass==null){
- styleClass="";
- }
- */
+ int delta = maxPages / 2;
- out.startElement("td", component);
- if (isCurrentPage) {
- out.writeAttribute("align", "center", null);
- //out.writeAttribute("class", "dr-dscr-act rich-datascr-act
"+scroller.getStyleClass(), null);
- out.writeAttribute("class", "dr-dscr-act rich-datascr-act",
null);
- out.writeAttribute("style", "" + scroller.getSelectedStyle(),
null);
- } else {
- out.writeAttribute("align", "center", null);
- //out.writeAttribute("class", "dr-dscr-inact rich-datascr-inact
"+scroller.getStyleClass(), null);
- out.writeAttribute("class", "dr-dscr-inact rich-datascr-inact",
null);
- //out.writeAttribute("style", ""+scroller.getStyle(), null);
- out.writeAttribute("onclick", getOnClick(context, component,
Integer.toString(i + 1)), null);
- }
- out.writeText(Integer.toString(i + 1), null);
- //renderChild(context, link);
- out.endElement("td");
- }
+ int pages;
+ int start;
+ if (pageCount > maxPages && currentPage > delta) {
+ pages = maxPages;
+ start = currentPage - pages / 2 - 1;
+ if (start + pages > pageCount) {
+ start = pageCount - pages;
+ }
+ } else {
+ pages = pageCount < maxPages ? pageCount : maxPages;
+ start = 0;
+ }
- }
+ for (int i = start, size = start + pages; i < size; i++) {
+ //String styleClass;
+ //String style;
- public void renderPages(FacesContext context, UIComponent component) throws IOException
{
- ComponentVariables variables = ComponentsVariableResolver.getVariables(this,
component);
- UIData data = (UIData) variables.getVariable("dataTable");
+ boolean isCurrentPage = (i + 1 == currentPage);
+ /*
+ if (isCurrentPage) {
+ styleClass = scroller.getSelectedStyleClass();
+ style = scroller.getSelectedStyle();
+ }
+ else {
+ styleClass = scroller.getStyleClass();
+ style = scroller.getStyle();
+ }
- ResponseWriter out = context.getResponseWriter();
- UIDatascroller scroller = (UIDatascroller) component;
- int currentPage = scroller.getPageIndex(data);
+ if (style==null){
+ style="";
+ }
+ if (styleClass==null){
+ styleClass="";
+ }
+ */
- int pageCount = scroller.getPageCount(data);
- if (pageCount <= 1) {
- pageCount = 1;
- }
- String varName = (String)scroller.getAttributes().get("pageIndexVar");
- if (varName != null && varName.length()>0)
- context.getExternalContext()
- .getRequestMap().put(varName, new Integer(currentPage));
- varName = (String)scroller.getAttributes().get("pagesVar");
- if (varName != null && varName.length()>0)
- context.getExternalContext()
- .getRequestMap().put(varName, new Integer(pageCount));
- }
+ out.startElement("td", component);
+ if (isCurrentPage) {
+ out.writeAttribute("align", "center", null);
+ //out.writeAttribute("class", "dr-dscr-act
rich-datascr-act "+scroller.getStyleClass(), null);
+ out.writeAttribute("class", "dr-dscr-act
rich-datascr-act",
+ null);
+ out.writeAttribute("style", "" +
scroller.getSelectedStyle(),
+ null);
+ } else {
+ out.writeAttribute("align", "center", null);
+ //out.writeAttribute("class", "dr-dscr-inact
rich-datascr-inact "+scroller.getStyleClass(), null);
+ out.writeAttribute("class", "dr-dscr-inact
rich-datascr-inact",
+ null);
+ //out.writeAttribute("style", ""+scroller.getStyle(),
null);
+ out.writeAttribute("onclick", getOnClick(context, component,
+ Integer.toString(i + 1)), null);
+ }
+ out.writeText(Integer.toString(i + 1), null);
+ //renderChild(context, link);
+ out.endElement("td");
+ }
- private Map getParamMap(FacesContext context) {
- return context.getExternalContext().getRequestParameterMap();
- }
+ }
- public String getOnClick(FacesContext context, UIComponent component, String value) {
+ public void renderPages(FacesContext context, UIComponent component)
+ throws IOException {
+ ComponentVariables variables = ComponentsVariableResolver.getVariables(
+ this, component);
+ UIData data = (UIData) variables.getVariable("dataTable");
- 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);
- function.addParameter(eventOptions);
- StringBuffer buffer = new StringBuffer();
- function.appendScript(buffer);
- buffer.append("; return false;");
- String script = buffer.toString();
- return script;
- }
+ ResponseWriter out = context.getResponseWriter();
+ UIDatascroller scroller = (UIDatascroller) component;
+ int currentPage = scroller.getPageIndex(data);
+ int pageCount = scroller.getPageCount(data);
+ if (pageCount <= 1) {
+ pageCount = 1;
+ }
+ String varName = (String)
scroller.getAttributes().get("pageIndexVar");
+ if (varName != null && varName.length() > 0) {
+ context.getExternalContext()
+ .getRequestMap().put(varName, new Integer(currentPage));
+ }
+ varName = (String) scroller.getAttributes().get("pagesVar");
+ if (varName != null && varName.length() > 0) {
+ context.getExternalContext()
+ .getRequestMap().put(varName, new Integer(pageCount));
+ }
+ }
- /**
- * Creates HtmlAjaxCommandLink sets its id, value and reRender and UIParameter
- */
- public boolean getRendersChildren() {
- return true;
- }
+ private Map getParamMap(FacesContext context) {
+ return context.getExternalContext().getRequestParameterMap();
+ }
+
+ public String getOnClick(FacesContext context, UIComponent component,
+ String value) {
+
+ 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);
+ function.addParameter(eventOptions);
+ StringBuffer buffer = new StringBuffer();
+ function.appendScript(buffer);
+ buffer.append("; return false;");
+ String script = buffer.toString();
+ return script;
+ }
+
+
+ /** Creates HtmlAjaxCommandLink sets its id, value and reRender and UIParameter */
+ public boolean getRendersChildren() {
+ return true;
+ }
}