3

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.

Ondra Žižka
  • 43,948
  • 41
  • 217
  • 277

2 Answers2

6

I don't know if you need a wicket-svg library anymore. But I have started a project at github to provide wicket components to work with svg.

Follow this link: wicket-svg

nschum
  • 15,322
  • 5
  • 58
  • 56
dzwicker
  • 71
  • 1
  • 5
2

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\">\n" +
            "\n" +
            "<svg width=\"100%\" height=\"100%\" version=\"1.1\"\n" +
            "xmlns=\"http://www.w3.org/2000/svg\">\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
  • 40,677
  • 6
  • 91
  • 113
  • 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 May 07 '10 at 03:38
  • 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 May 07 '10 at 09:59
  • Thanks for providing this example. Unfortunately it does not work out-of-the-box with Wicket 9.x. The `onRender` method doesn't have a parameter anymore and it seems to me that we need to provide a dummy (i.e. empty) implementation of the `getMarkup` method. But with that I could get your blue rectangle. – jmizv Jun 16 '23 at 07:16