views:

141

answers:

1

SVG DOM can be controlled with JavaScript, so it can be AJAX-enabled... I wonder if there are some SVG components for Wicket yet. And if Wicket can have pure xml/svg as the output format.

Quick googling shows only a question at Code Ranch.

+1  A: 

I don't know of components built, but Wicket definitely can have xml/svg as output format, and it's quite simple to make a Page that renders svg.

Dumb simple example code:

public class Rectangle extends Page {

    @Override
    public String getMarkupType() {
        return "xml/svg";
    }

    @Override
    protected void onRender(MarkupStream markupStream) {
        PrintWriter writer = new PrintWriter(getResponse().getOutputStream());
        writer.write(makeRectangleSVG());
        writer.flush();
        writer.close();
    }

    private String makeRectangleSVG() {
        return "<?xml version=\"1.0\" standalone=\"no\"?>\n" +
            "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n" +
            "\"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\"&gt;\n" +
            "\n" +
            "<svg width=\"100%\" height=\"100%\" version=\"1.1\"\n" +
            "xmlns=\"http://www.w3.org/2000/svg\"&gt;\n" +
            "\n" +
            "<rect width=\"300\" height=\"100\"\n" +
            "style=\"fill:rgb(0,0,255);stroke-width:1;\n" +
            "stroke:rgb(0,0,0)\"/>\n" +
            "\n" +
            "</svg> ";
    }
}

If you map this as a bookmarkable page and call it up, it does display a lovely blue rectangle, as per the hard-coded svg (stolen from a w3schools example). And of course you could easily parametrize the page and generate the svg instead of just sending a constant string...

I suspect it also wouldn't be hard to build a component based on the object tag so that svg could be shown as part of an html page rather than being the whole page like this, but I haven't yet tried to do so.

Don Roby
Thanks, but I meant some compoments leveraging Wicket's events to handle user's actions. For a "hand-generated" `xml/svg` output, I'd rather use simple servlet.
Ondra Žižka
I expect to use Wicket for what you're after, you'd still want something similar to this, but as a component based on the object tag with redrawing on user event. I don't think they're already out there.
Don Roby