Hello everyone,
this my first post to the list, so I would like to give many thanks to the 
authors and all contributors to the great Apache Wicket project. We silently 
develop a medium sized application for over two years (at the Warsaw University 
of Technology), and usually we have resolved all issues by searching answers on 
this users group or by googling them. This time I would ask you for 
consultation.

My goal is to provide a download link for CSV data which will be generated 
dynamically and during the time consuming generation I would like to show a 
user an indicator. Like the one the IndicatingAjaxLink class do.

My questions are:

1) Is the following source code created the 'wicket way' or I am breaking 
somewhere else opened door?
The 'trick' I have employed, that I am not sure of, is the redirection to the 
AbstractDefaultAjaxBehaviour in the onClick method of the IndicatingAjaxLink.

2) The problem with this code is that, when I click the download link the 
second time the indicator is not revolving. It is being displayed correctly, 
and hidden on time, and the CSV data is exported correctly. The problem is that 
the indicator is not moving.

Thank you for you assitance in advance,
Robert Szmurlo

Java:

public class HomePage extends WebPage {

    private AbstractDefaultAjaxBehavior b;
    private String data = null;

    public HomePage(final PageParameters parameters) {

        final ByteArrayResource bar = new ByteArrayResource("text/csv") {
            @Override
            public byte[] getData(Attributes attributes) {
                byte[] bytes = null;
                try {
                    bytes = data.getBytes();
                } catch (Exception e) {
                    e.printStackTrace();
                }
                return bytes;
            }

            @Override
            protected void configureResponse(ResourceResponse 
response,Attributes attributes) {
                super.configureResponse(response, attributes);
                response.setFileName("report.csv");
            }

        };

        add( b = new AbstractDefaultAjaxBehavior() {
            @Override
            protected void respond(AjaxRequestTarget target) {
                getRequestCycle().scheduleRequestHandlerAfterCurrent(new 
ResourceRequestHandler(bar, getPageParameters()));
            }
        });

        add( new IndicatingAjaxLink<Void>("link") {
            @Override
            public void onClick(AjaxRequestTarget target) {

                prepareData(); // takes some time

                if (target != null) {
*target.appendJavaScript("window.location='" + b.getCallbackUrl() + "'");*
                }
            }
        });
    }

    protected void prepareData() {
        ////////// JUST FOR TEST
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        /////////////////////////

        // atach data?
        data = "No.;Name\n" +
               "1.;John\n" +
               "2.;Mary";
    }
}


HTML:
<html>
<body>
<a wicket:id="link">Export CSV</a>
</body>
</html>

Reply via email to