James,

I've done this before, for exactly the same reason. My solution was as follows:

I wrote a component that sat in the form, and every 0.25 seconds set the value of a hidden field to the current scroll position using Javascript, and then output Javascript that when the form was redisplayed as part of the next request, auto-scrolled it to the correct location.

Sounds absolutely hideous, but it worked beautifully, and wasn't that tricky to implement -- think it was a few tens of lines of real code to write the component, and then it was just a case of embedding it in the relevant forms. The user experience was sufficiently good (over a fast connection) to prompt people to believe I was using AJAX.

The code and JWC I used is below (packages declarations removed from both files to protect the innocent!). The .html was just empty since the component renders itself in code. Literally all you have to do to use it is embed the component within your form.

Hope that helps...


Paul

=====--------
= Scroller.Java


import org.apache.tapestry.IMarkupWriter;
import org.apache.tapestry.IRequestCycle;
import org.apache.tapestry.PageRenderSupport;
import org.apache.tapestry.TapestryUtils;
import org.apache.tapestry.form.AbstractFormComponent;

public abstract class Scroller extends AbstractFormComponent {
        public abstract int getCurrentX();
        public abstract void setCurrentX(int pX);
        
        public abstract int getCurrentY();
        public abstract void setCurrentY(int pY);
        
        public abstract boolean isScrollingInformationAvailable();
public abstract void setScrollingInformationAvailable(boolean pScrollingInformationAvailable);

protected void renderFormComponent(IMarkupWriter pWriter, IRequestCycle pRC) {
                PageRenderSupport lPRS = 
TapestryUtils.getPageRenderSupport(pRC,this);
                
                StringBuffer lBodyScript = new StringBuffer();
lBodyScript.append("function updateScrollLocation" + getName() + "() {\n"); lBodyScript.append("\tif (document.documentElement && document.documentElement.scrollTop) {\n");
                lBodyScript.append("\t\tx = 
document.documentElement.scrollLeft;\n");
                lBodyScript.append("\t\ty = 
document.documentElement.scrollTop;\n");
                lBodyScript.append("\t} else if (document.body) {\n");
                lBodyScript.append("\t\tx = document.body.scrollLeft;\n");
                lBodyScript.append("\t\ty = document.body.scrollTop;\n");
                lBodyScript.append("\t} else {\n");
                lBodyScript.append("\t\tvar x = window.pageXOffset;\n");
                lBodyScript.append("\t\tvar y = window.pageYOffset;\n");
                lBodyScript.append("\t}\n");
                
lBodyScript.append("\tdocument.getElementsByName('" + getName() + "')[0].value=x + ',' + y;\n");
                lBodyScript.append("\treturn true;");
                lBodyScript.append("}\n");
                lPRS.addBodyScript(lBodyScript.toString());
                
lPRS.addInitializationScript("setInterval('updateScrollLocation" + getName() + "()',250);updateScrollLocation" + getName() + "();\n");
                if ( isScrollingInformationAvailable() ) {
lPRS.addInitializationScript("window.scrollTo(" + getCurrentX() + "," + getCurrentY() + ");\n");
                }
                
                pWriter.begin("input");
                pWriter.attribute("type","hidden");
                pWriter.attribute("value","0,0");
                pWriter.attribute("name",this.getName());
                pWriter.end();
        }
        
protected void rewindFormComponent(IMarkupWriter pWriter, IRequestCycle pRC) {
                String lValue = pRC.getParameter(getName());
                if ( lValue != null ) {
                        int lPivot = lValue.indexOf(",");
                        
setCurrentX(Integer.parseInt(lValue.substring(0,lPivot)));
                        setCurrentY(Integer.parseInt(lValue.substring(lPivot + 
1)));
                        setScrollingInformationAvailable(true);
                } else {
                        setScrollingInformationAvailable(false);
                }
        }

}

=====--------
= Scroller.jwc
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE component-specification
PUBLIC "-//Apache Software Foundation//Tapestry Specification 4.0// EN"
  "http://jakarta.apache.org/tapestry/dtd/Tapestry_4_0.dtd";>

<component-specification class="Scroller" allow-body="no" allow- informal-parameters="no">

</component-specification>




On 6 Jul 2006, at 15:42, James Carman wrote:

All,

Does anyone know how to get Tapestry to "stay put" on a screen when you submit the form and reshow it? I have a form that is somewhat long. When I use an event (like selecting something in a drop-down box) that forces a form submit to refresh some other parts of the screen, the screen goes back up to the top. I would like it to just stay where it is (somewhere near the
originating drop-down).  Any ideas?

James



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to