01: /**
02: * Copyright 2006 Webmedia Group Ltd.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: **/package org.araneaframework.jsp.tag.basic;
16:
17: import java.io.Writer;
18: import org.araneaframework.http.WindowScrollPositionContext;
19: import org.araneaframework.jsp.tag.BaseTag;
20: import org.araneaframework.jsp.util.JspUtil;
21:
22: /**
23: * Tag that registers functions dealing with window scroll position storing and restoring.
24: * @author Taimo Peelo (taimo@araneaframework.org)
25: *
26: * @jsp.tag
27: * name = "registerScrollHandler"
28: * body-content = "empty"
29: * description = "Registers popups present in current popupcontext for opening. For this tag to work, produced HTML file BODY should have attribute onload='processLoadEvents()'".
30: */
31: public class ScrollHandlerRegistrationHtmlTag extends BaseTag {
32: protected int doEndTag(Writer out) throws Exception {
33: WindowScrollPositionContext scrollHandler = (WindowScrollPositionContext) getEnvironment()
34: .getEntry(WindowScrollPositionContext.class);
35:
36: if (scrollHandler != null) {
37: registerScrollHandler(out, scrollHandler);
38: }
39:
40: return EVAL_PAGE;
41: }
42:
43: protected void registerScrollHandler(Writer out,
44: WindowScrollPositionContext scrollHandler) throws Exception {
45: String x = scrollHandler.getX();
46: String y = scrollHandler.getY();
47:
48: JspUtil.writeHiddenInputElement(out,
49: WindowScrollPositionContext.WINDOW_SCROLL_X_KEY,
50: x != null ? x : "0");
51: JspUtil.writeHiddenInputElement(out,
52: WindowScrollPositionContext.WINDOW_SCROLL_Y_KEY,
53: y != null ? y : "0");
54:
55: out.write("<script type=\"text/javascript\">");
56: // ensure restoration of scroll position
57: out
58: .write("_ap.addClientLoadEvent(function() { var form = _ap.getSystemForm();"
59: + " if (form."
60: + WindowScrollPositionContext.WINDOW_SCROLL_X_KEY
61: + " && form."
62: + WindowScrollPositionContext.WINDOW_SCROLL_Y_KEY
63: + ") "
64: + "Aranea.UI.scrollToCoordinates("
65: + x
66: + "," + y + ");});");
67: //"form."+ WindowScrollPositionContext.WINDOW_SCROLL_X_KEY + ".value, " +
68: //"form."+ WindowScrollPositionContext.WINDOW_SCROLL_Y_KEY + ".value);});");
69:
70: // ensure that the scroll coordinates are submitted with request
71: out
72: .write("_ap.addSubmitCallback(function() {Aranea.UI.saveScrollCoordinates()});");
73: out.write("</script>");
74: }
75: }
|