开发者

Wicket and SVG - any components exist?

开发者 https://www.devze.com 2022-12-28 17:28 出处:网络
SVG DOM can be controlled with JavaScript, so it开发者_StackOverflow 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

SVG DOM can be controlled with JavaScript, so it开发者_StackOverflow 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.


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号