You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by we...@apache.org on 2007/01/14 13:44:07 UTC
svn commit: r496077 - in /myfaces/tobago/trunk:
core/src/main/java/org/apache/myfaces/tobago/component/
core/src/main/java/org/apache/myfaces/tobago/model/
theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/ta...
Author: weber
Date: Sun Jan 14 04:44:06 2007
New Revision: 496077
URL: http://svn.apache.org/viewvc?view=rev&rev=496077
Log:
TOBAGO-229 (AJAX-reload of scrollable Sheets resets scrollbar to top position)
Modified:
myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/UIData.java
myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/model/SheetState.java
myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/SheetRenderer.java
myfaces/tobago/trunk/theme/standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-sheet.js
Modified: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/UIData.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/UIData.java?view=diff&rev=496077&r1=496076&r2=496077
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/UIData.java (original)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/UIData.java Sun Jan 14 04:44:06 2007
@@ -71,6 +71,7 @@
public static final String FACET_SORTER = "sorter";
public static final String SORTER_ID = "sorter";
+ public static final String ATTR_SCROLL_POSITION = "attrScrollPosition";
public static final String NONE = "none";
public static final String SINGLE = "single";
@@ -481,10 +482,12 @@
// getSortActionListener();
// state.setSortedColumn(sortActionListener != null ? sortActionListener.getColumn() : -1);
// state.setAscending(sortActionListener != null && sortActionListener.isAscending());
- state.setSelectedRows((List<Integer>)
- getAttributes().get(ATTR_SELECTED_LIST_STRING));
- state.setColumnWidths((String)
- getAttributes().get(ATTR_WIDTH_LIST_STRING));
+ Map attributes = getAttributes();
+ //noinspection unchecked
+ state.setSelectedRows((List<Integer>) attributes.get(ATTR_SELECTED_LIST_STRING));
+ state.setColumnWidths((String) attributes.get(ATTR_WIDTH_LIST_STRING));
+ state.setScrollPosition((Integer[]) attributes.get(ATTR_SCROLL_POSITION));
+ attributes.remove(ATTR_SCROLL_POSITION);
}
}
@@ -660,5 +663,13 @@
} else {
AjaxUtils.processAjaxOnChildren(facesContext, this);
}
+ }
+
+ public Integer[] getScrollPosition() {
+ Integer[] scrollPosition = (Integer[]) getAttributes().get(ATTR_SCROLL_POSITION);
+ if (scrollPosition == null) {
+ scrollPosition = getSheetState(FacesContext.getCurrentInstance()).getScrollPosition();
+ }
+ return scrollPosition;
}
}
Modified: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/model/SheetState.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/model/SheetState.java?view=diff&rev=496077&r1=496076&r2=496077
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/model/SheetState.java (original)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/model/SheetState.java Sun Jan 14 04:44:06 2007
@@ -19,13 +19,16 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.commons.lang.StringUtils;
+
import org.apache.myfaces.tobago.event.SortActionEvent;
import javax.faces.component.UIColumn;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
-// TODO find a better solution for this
+
+// TODO find a better solution for this
public class SheetState implements Serializable {
private static final Log LOG = LogFactory.getLog(SheetState.class);
@@ -36,6 +39,7 @@
private boolean ascending;
private String columnWidths;
private List<Integer> selectedRows;
+ private Integer[] scrollPosition;
public SheetState() {
resetSelected();
@@ -97,5 +101,30 @@
ascending = true;
sortedColumnId = actualColumn.getId();
}
+ }
+
+ public Integer[] getScrollPosition() {
+ return scrollPosition;
+ }
+
+ public void setScrollPosition(Integer[] scrollPosition) {
+ this.scrollPosition = scrollPosition;
+ }
+
+ public static Integer[] parseScrollPosition(String value) {
+ Integer[] position = null;
+ if (!StringUtils.isBlank(value)) {
+ int sep = value.indexOf(";");
+ LOG.info("value = \"" + value + "\" sep = " + sep + "");
+ if (sep == -1) {
+ throw new NumberFormatException(value);
+ }
+ int left = Integer.parseInt(value.substring(0, sep));
+ int top = Integer.parseInt(value.substring(sep + 1));
+ position = new Integer[2];
+ position[0] = left;
+ position[1] = top;
+ }
+ return position;
}
}
Modified: myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/SheetRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/SheetRenderer.java?view=diff&rev=496077&r1=496076&r2=496077
==============================================================================
--- myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/SheetRenderer.java (original)
+++ myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/SheetRenderer.java Sun Jan 14 04:44:06 2007
@@ -22,6 +22,8 @@
* $Id$
*/
+import static org.apache.myfaces.tobago.component.UIData.ATTR_SCROLL_POSITION;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import static org.apache.myfaces.tobago.TobagoConstants.ATTR_ACTION_ONCLICK;
@@ -105,6 +107,10 @@
public static final String WIDTHS_POSTFIX
= SUBCOMPONENT_SEP + "widths";
+
+ public static final String SCROLL_POSTFIX
+ = SUBCOMPONENT_SEP + "scrollPosition";
+
public static final String SELECTED_POSTFIX
= SUBCOMPONENT_SEP + "selected";
private static final Integer HEIGHT_0 = 0;
@@ -219,6 +225,19 @@
writer.writeAttribute(HtmlAttributes.VALUE, "", null);
writer.endElement(HtmlConstants.INPUT);
+ writer.startElement(HtmlConstants.INPUT, null);
+ writer.writeIdAttribute(sheetId + SCROLL_POSTFIX);
+ writer.writeNameAttribute(sheetId + SCROLL_POSTFIX);
+ writer.writeAttribute(HtmlAttributes.TYPE, "hidden", null);
+ Integer[] scrollPosition = data.getScrollPosition();
+ if (scrollPosition != null) {
+ String scroll = scrollPosition[0] + ";" + scrollPosition[1];
+ writer.writeAttribute(HtmlAttributes.VALUE, scroll, null);
+ } else {
+ writer.writeAttribute(HtmlAttributes.VALUE, "", null);
+ }
+ writer.endElement(HtmlConstants.INPUT);
+
if (!NONE.equals(selectable)) {
writer.startElement(HtmlConstants.INPUT, null);
writer.writeIdAttribute(sheetId + SELECTED_POSTFIX);
@@ -592,6 +611,17 @@
component.getAttributes().put(
ATTR_SELECTED_LIST_STRING, selectedRows);
}
+
+ key = component.getClientId(facesContext) + SCROLL_POSTFIX;
+ String value = (String) requestParameterMap.get(key);
+ if (value != null) {
+ Integer[] scrollPosition = SheetState.parseScrollPosition(value);
+ if (scrollPosition != null) {
+ //noinspection unchecked
+ component.getAttributes().put(ATTR_SCROLL_POSITION, scrollPosition);
+ }
+ }
+
}
public boolean needVerticalScrollbar(FacesContext facesContext, UIData data) {
Modified: myfaces/tobago/trunk/theme/standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-sheet.js
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/theme/standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-sheet.js?view=diff&rev=496077&r1=496076&r2=496077
==============================================================================
--- myfaces/tobago/trunk/theme/standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-sheet.js (original)
+++ myfaces/tobago/trunk/theme/standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-sheet.js Sun Jan 14 04:44:06 2007
@@ -62,6 +62,7 @@
this.contentDivId = this.id + "_data_div";
this.selectedId = this.id + Tobago.SUB_COMPONENT_SEP +"selected";
this.headerWidthsId = this.id + Tobago.SUB_COMPONENT_SEP + "widths"
+ this.scrollPositionId = this.id + Tobago.SUB_COMPONENT_SEP + "scrollPosition";
if (this.ajaxEnabled) {
Tobago.ajaxComponents[this.id] = this;
@@ -367,6 +368,7 @@
this.tobagoLastClickedRowId = this.firstRowIndex;
}
this.adjustScrollBars();
+ this.setScrollPosition();
if (this.selectable && (this.selectable == "single" || this.selectable == "multi")) {
this.addSelectionListener();
@@ -384,6 +386,24 @@
this.setupEnd = new Date();
};
+Tobago.Sheet.prototype.setScrollPosition = function() {
+ var hidden = Tobago.element(this.scrollPositionId);
+ if (hidden) {
+ var sep = hidden.value.indexOf(";");
+ if (sep != -1) {
+ var scrollLeft = hidden.value.substr(0, sep);
+ var scrollTop = hidden.value.substr(sep + 1);
+ var contentDiv = Tobago.element(this.contentDivId);
+ contentDiv.scrollLeft = scrollLeft;
+ contentDiv.scrollTop = scrollTop;
+ var headerDiv = Tobago.element(this.headerDivId);
+ if (headerDiv) {
+ headerDiv.scrollLeft = contentDiv.scrollLeft;
+ }
+ }
+ }
+}
+
Tobago.Sheet.prototype.initReload = function() {
if (typeof this.autoReload == "number" && Tobago.element(this.contentDivId)) {
Tobago.addReloadTimeout(this.id, Tobago.bind2(this, "reloadWithAction", this.id), this.autoReload);
@@ -714,8 +734,13 @@
Tobago.Sheet.prototype.doScroll = function(event) {
//LOG.debug("header / data " + this.headerDiv.scrollLeft + "/" + this.contentDiv.scrollLeft);
var headerDiv = Tobago.element(this.headerDivId);
+ var contentDiv = Tobago.element(this.contentDivId);
if (headerDiv) {
- headerDiv.scrollLeft = Tobago.element(this.contentDivId).scrollLeft;
+ headerDiv.scrollLeft = contentDiv.scrollLeft;
+ }
+ var hidden = Tobago.element(this.scrollPositionId);
+ if (hidden) {
+ hidden.value = contentDiv.scrollLeft + ";" + contentDiv.scrollTop;
}
//LOG.debug("header / data " + this.headerDiv.scrollLeft + "/" + this.contentDiv.scrollLeft);
//LOG.debug("----------------------------------------------");