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 2013/08/26 11:50:13 UTC
svn commit: r1517481 - in /myfaces/tobago/trunk/tobago-theme:
tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/
tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/util/
tobago...
Author: weber
Date: Mon Aug 26 09:50:13 2013
New Revision: 1517481
URL: http://svn.apache.org/r1517481
Log:
TOBAGO-1304 - tree looses scroll position after expanding node
Modified:
myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/SheetRenderer.java
myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TreeRenderer.java
myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/util/RenderUtils.java
myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago.js
Modified: myfaces/tobago/trunk/tobago-theme/tobago-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/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/SheetRenderer.java?rev=1517481&r1=1517480&r2=1517481&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/SheetRenderer.java (original)
+++ myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/SheetRenderer.java Mon Aug 26 09:50:13 2013
@@ -193,18 +193,7 @@ public class SheetRenderer extends Layou
writer.writeAttribute(HtmlAttributes.VALUE, StringUtils.joinWithSurroundingSeparator(columnWidths), false);
writer.endElement(HtmlElements.INPUT);
- writer.startElement(HtmlElements.INPUT, null);
- writer.writeIdAttribute(sheetId + SCROLL_POSTFIX);
- writer.writeNameAttribute(sheetId + SCROLL_POSTFIX);
- writer.writeAttribute(HtmlAttributes.TYPE, HtmlInputTypes.HIDDEN, false);
- Integer[] scrollPosition = sheet.getScrollPosition();
- if (scrollPosition != null) {
- String scroll = scrollPosition[0] + ";" + scrollPosition[1];
- writer.writeAttribute(HtmlAttributes.VALUE, scroll, false);
- } else {
- writer.writeAttribute(HtmlAttributes.VALUE, "", false);
- }
- writer.endElement(HtmlElements.INPUT);
+ RenderUtils.writeScrollPosition(facesContext, writer, sheet, sheet.getScrollPosition());
if (!UISheet.NONE.equals(selectable)) {
writer.startElement(HtmlElements.INPUT, null);
@@ -618,16 +607,7 @@ public class SheetRenderer extends Layou
sheet.getAttributes().put(Attributes.SELECTED_LIST_STRING, selectedRows);
}
- key = sheet.getClientId(facesContext) + SCROLL_POSTFIX;
- String value = (String) requestParameterMap.get(key);
- if (value != null) {
- Integer[] scrollPosition = SheetState.parseScrollPosition(value);
- if (scrollPosition != null) {
- //noinspection unchecked
- sheet.getAttributes().put(Attributes.SCROLL_POSITION, scrollPosition);
- }
- }
-
+ RenderUtils.decodeScrollPosition(facesContext, sheet);
RenderUtils.decodedStateOfTreeData(facesContext, sheet);
}
Modified: myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TreeRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TreeRenderer.java?rev=1517481&r1=1517480&r2=1517481&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TreeRenderer.java (original)
+++ myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TreeRenderer.java Mon Aug 26 09:50:13 2013
@@ -50,6 +50,7 @@ public class TreeRenderer extends Layout
@Override
public void decode(FacesContext facesContext, UIComponent component) {
+ RenderUtils.decodeScrollPosition(facesContext, component);
final AbstractUITree tree = (AbstractUITree) component;
RenderUtils.decodedStateOfTreeData(facesContext, tree);
}
@@ -85,6 +86,7 @@ public class TreeRenderer extends Layout
writer.writeStyleAttribute(style);
writer.writeIdAttribute(clientId);
HtmlRendererUtils.writeDataAttributes(facesContext, writer, tree);
+ writer.writeAttribute("data-tobago-scroll-panel", "true", true);
final Selectable selectable = tree.getSelectableAsEnum();
if (selectable.isSupportedByTree()) {
@@ -141,6 +143,8 @@ public class TreeRenderer extends Layout
writer.writeAttribute(HtmlAttributes.VALUE, expandedValue.toString(), false);
writer.endElement(HtmlElements.INPUT);
+ RenderUtils.writeScrollPosition(facesContext, writer, tree);
+
writer.endElement(HtmlElements.DIV);
}
Modified: myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/util/RenderUtils.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/util/RenderUtils.java?rev=1517481&r1=1517480&r2=1517481&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/util/RenderUtils.java (original)
+++ myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/util/RenderUtils.java Mon Aug 26 09:50:13 2013
@@ -30,8 +30,13 @@ import org.apache.myfaces.tobago.model.E
import org.apache.myfaces.tobago.model.SelectedState;
import org.apache.myfaces.tobago.model.TreePath;
import org.apache.myfaces.tobago.renderkit.RendererBase;
+import org.apache.myfaces.tobago.renderkit.html.HtmlAttributes;
+import org.apache.myfaces.tobago.renderkit.html.HtmlElements;
+import org.apache.myfaces.tobago.renderkit.html.HtmlInputTypes;
import org.apache.myfaces.tobago.util.ComponentUtils;
import org.apache.myfaces.tobago.util.DebugUtils;
+import org.apache.myfaces.tobago.webapp.TobagoResponseWriter;
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -67,6 +72,8 @@ public class RenderUtils {
@Deprecated
public static final String COMPONENT_IN_REQUEST = "org.apache.myfaces.tobago.component";
+ public static final String SCROLL_POSTFIX = ComponentUtils.SUB_SEPARATOR + "scrollPosition";
+
private RenderUtils() {
// to prevent instantiation
}
@@ -439,6 +446,66 @@ public class RenderUtils {
return null;
}
+ public static void writeScrollPosition(FacesContext facesContext, TobagoResponseWriter writer, UIComponent component)
+ throws IOException {
+ Integer[] scrollPosition = (Integer[]) component.getAttributes().get(Attributes.SCROLL_POSITION);
+ if (scrollPosition == null) {
+ final String key = component.getClientId(facesContext) + SCROLL_POSTFIX;
+ scrollPosition = parseScrollPosition(facesContext.getExternalContext().getRequestParameterMap().get(key));
+ }
+ writeScrollPosition(facesContext, writer, component, scrollPosition);
+ }
+
+ public static void writeScrollPosition(
+ FacesContext facesContext, TobagoResponseWriter writer, UIComponent component, Integer[] scrollPosition)
+ throws IOException {
+ final String clientId = component.getClientId(facesContext);
+ writer.startElement(HtmlElements.INPUT, null);
+ writer.writeIdAttribute(clientId + SCROLL_POSTFIX);
+ writer.writeNameAttribute(clientId + SCROLL_POSTFIX);
+ writer.writeAttribute(HtmlAttributes.TYPE, HtmlInputTypes.HIDDEN, false);
+ if (scrollPosition != null) {
+ String scroll = scrollPosition[0] + ";" + scrollPosition[1];
+ writer.writeAttribute(HtmlAttributes.VALUE, scroll, false);
+ } else {
+ writer.writeAttribute(HtmlAttributes.VALUE, "", false);
+ }
+ writer.writeAttribute("data-tobago-scroll-position", "true", true);
+ writer.endElement(HtmlElements.INPUT);
+ }
+
+ public static void decodeScrollPosition(FacesContext facesContext, UIComponent component) {
+ String key;
+ key = component.getClientId(facesContext) + SCROLL_POSTFIX;
+ String value = (String) facesContext.getExternalContext().getRequestParameterMap().get(key);
+ if (value != null) {
+ Integer[] scrollPosition = parseScrollPosition(value);
+ if (scrollPosition != null) {
+ //noinspection unchecked
+ component.getAttributes().put(Attributes.SCROLL_POSITION, scrollPosition);
+ }
+ }
+ }
+
+ public static Integer[] parseScrollPosition(String value) {
+ Integer[] position = null;
+ if (!org.apache.commons.lang.StringUtils.isBlank(value)) {
+ int sep = value.indexOf(";");
+ if (LOG.isInfoEnabled()) {
+ 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;
+ }
+
public static String generateUrl(FacesContext facesContext, AbstractUICommandBase component) {
final Application application = facesContext.getApplication();
Modified: myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago.js
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago.js?rev=1517481&r1=1517480&r2=1517481&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago.js (original)
+++ myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago.js Mon Aug 26 09:50:13 2013
@@ -980,6 +980,35 @@ var Tobago = {
new Tobago.AcceleratorKey(function clickAccelKey() {
Tobago.clickOnElement(el.attr("id"))}, el.attr("accesskey"));
});
+
+ Tobago.initScrollPosition(elements ? elements : jQuery("body"));
+ },
+
+ initScrollPosition: function(elements) {
+ var scrollPanels;
+ if (elements.data("tobago-scroll-panel")) {
+ scrollPanels = elements;
+ } else {
+ scrollPanels = elements.find("[data-tobago-scroll-panel]");
+ }
+ scrollPanels.bind("scroll", function () {
+ var panel = jQuery(this);
+ var scrollLeft = panel.prop("scrollLeft");
+ var scrollTop = panel.prop("scrollTop");
+ // store the position in a hidden field
+ panel.children("[data-tobago-scroll-position]").val(scrollLeft + ";" + scrollTop);
+ });
+ scrollPanels.each(function () {
+ var panel = jQuery(this);
+ var hidden = panel.children("[data-tobago-scroll-position]");
+ var sep = hidden.val().indexOf(";");
+ if (sep != -1) {
+ var scrollLeft = hidden.val().substr(0, sep);
+ var scrollTop = hidden.val().substr(sep + 1);
+ panel.prop("scrollLeft", scrollLeft);
+ panel.prop("scrollTop", scrollTop);
+ }
+ });
},
initCss: function(elements) {