6 October 2007
DWR
I can't heap enough praise on the JavaScript library DWR (direct web remoting). It came to my attention a few months back, but I've only now been able to really dive in an use it. DWR dynamically generates JavaScript classes from the Java classes of your choice. Any calls beyond simple set/get are implemented as Ajax calls back to the server. DWR allows you to leverage your existing Java code without reimplementing in JavaScript.
Given the Java class Users that manages system users with the User class, we could have the following simplified script in a page:
<script type="text/javascript"> // Ajax call to server with JavaScript callback Users.findActive(showActiveUsers); // Callback passed collection of User objects, populate page as needed function showActiveUsers(users) { $A(users).each(function(user) { new Insertion.Bottom( "myDiv", "<p>" + user.name + ": " + user.id + "</p>); }) } </script>
Voila. JavaScript code becomes an extension of your Java code (with a little help from the equally invaluable Prototype library).
[ posted by sstrader on
6 October 2007 at 12:35:44 PM in Programming
]
- Techniques after using Swift for a month posted by sstrader on 26 August 2015 at 11:41:51 PM
- Some thoughts on Ruby after finishing a week (minus one day) of training posted by sstrader on 15 December 2011 at 8:59:30 PM
- Links on the singleton pattern posted by sstrader on 9 December 2011 at 9:19:50 AM
- Phonebot posted by sstrader on 29 October 2011 at 6:37:05 PM
- The labeled break in Java posted by sstrader on 4 September 2011 at 11:27:56 AM
Related entries
Other entries categorized in Programming: