tags:

views:

702

answers:

2

I am using JSF frontend for a page where an image is uploaded or deleted. Clicking on the upload or delete button causes a postback and the page to reload with the updated status. This however, resets the scroll position of the page. How should I go about retaining the scrollback of this page on the postback actions.

A: 

If you are using Apache MyFaces Tomahawk, you can set the parameter AUTOSCROLL then make sure AutoScrollPhaseListener is enabled.

I'm not sure this functionality is specified by JSF, but instead is something extra implemented by Apache MyFaces Tomahawk.

Also, be aware that prior to version 1.1.6, there is a cross-site scripting vulnerability in the AUTOSCROLL implementation.

shadit
A: 

You can do that with an actionListener. For example, in your page (page.jsf for example):

<f:view>    
    <h:form>
        <h:commandLink actionListener="#{bean.method}">
            <h:outputText value="Submit" />
            <f:param name="anchor" value="image" />
        </h:commandLink>
    </h:form>
    <div id='result'>
        <h1><a name='image'>Image</a></h1>        
    </div>
</f:view>

And the managed bean looks like:

public class Bean {

    public void method(ActionEvent actionEvent) {

        // Get parameter
        String ancla = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("anchor");

        try {
            FacesContext.getCurrentInstance().getExternalContext().redirect("page.jsf#" + anchor);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}

Hope this helps

Fede