I write a lot on this blog about customizing Metawidget for different scenarios. But it's worth stressing Metawidget also works as a lightweight, no fuss solution out-of-the-box.
For example, say you just wanted to quickly render a JSON object on the client. Here's the entire code:
<!DOCTYPE HTML>
<html>
<head>
<script src="js/lib/metawidget-core.min.js"></script>
<style>
#metawidget {
border: 1px solid #cccccc;
width: 250px;
border-radius: 10px;
padding: 10px;
margin: 50px auto;
}
</style>
</head>
<body>
<div id="metawidget"></div>
<script type="text/javascript">
var mw = new metawidget.Metawidget( document.getElementById( 'metawidget' ));
mw.toInspect = {
firstname: 'Homer',
surname: 'Simpson',
age: 36
};
mw.buildWidgets();
</script>
</body>
</html>
<html>
<head>
<script src="js/lib/metawidget-core.min.js"></script>
<style>
#metawidget {
border: 1px solid #cccccc;
width: 250px;
border-radius: 10px;
padding: 10px;
margin: 50px auto;
}
</style>
</head>
<body>
<div id="metawidget"></div>
<script type="text/javascript">
var mw = new metawidget.Metawidget( document.getElementById( 'metawidget' ));
mw.toInspect = {
firstname: 'Homer',
surname: 'Simpson',
age: 36
};
mw.buildWidgets();
</script>
</body>
</html>
This will handily render:
Of course you can go much (much) deeper, but for once I'll resist the temptation to show that. If you're interested, start with the tutorial here.


6 comments:
Does the java version support json too ?
Hi Max,
Not at this time, no. However that should be pretty easy to write. Can you give me a scenario you'd like it to cover?
Regards,
Richard.
Well, by this blog I just realized it could be interesting to try use metawidget for our webservice tester in JBoss Tools - it supports wsdl and rest but it would mostly be for rest to allow editing and presenting the json response.
Thinking about pointing metawidget on a piece of json or wsdl xml and let it edit it but I guess I would still need to convert the UI back into json/wsdl ;)
Just a thought.
What would be your preferred UI framework for this (SWT, JSF, GWT etc)?
that would be for SWT since it would be in the eclipse tooling first....but the general comprehension of json into what fields and types it has we could use independently of any UI framework.
i.e. to "scaffold" based on a rest/json service.
Hi Max,
Apologies for the delay. I have written a new blog for using JSON with SWT: http://blog.kennardconsulting.com/2013/04/java-based-json-and-json-schema-user.html
Could you please download the latest 3.3-SNAPSHOT release and give it a go? https://repository.jboss.org/nexus/content/repositories/snapshots/org/metawidget/modules/metawidget-all/3.3-SNAPSHOT/
Regards,
Richard.
Post a Comment