{"id":103,"date":"2007-03-23T19:23:31","date_gmt":"2007-03-23T18:23:31","guid":{"rendered":"http:\/\/blog.pczone.be\/?p=103"},"modified":"2007-03-23T10:33:32","modified_gmt":"2007-03-23T09:33:32","slug":"dwr","status":"publish","type":"post","link":"https:\/\/blog.pczone.be\/?p=103","title":{"rendered":"DWR"},"content":{"rendered":"<p>In one of my projects the user has to select a customer from a dropdown list. Problem is that the number of customers they have is much to big to prefill. So I used dwr to build a solution. The user has a dropdown from which he can choose the field he wants to query (let&#8217;s say street), he than fills in a streetname, presses the button and the list gets prefilled with the list of customers who match.<\/p>\n<p>How does it work. Wel really simple \ud83d\ude42<\/p>\n<p>In my backend I have a simple POJO Search with a method getCustomers(String searchField,String searchValue). This calls a service layer, who in turn calls a dao layer,&#8230; you know the drill. In the end the method will return a List of Customer objects. I exposed these objects in the dwr.xml configuration file. (that&#8217;s it for the java backend stuff) (nice isn&#8217;t it \ud83d\ude42 )<\/p>\n<p>Now the javascript part is also small and handy. I had to include the dwr engine and my exposed object as javascript objects. When the user presses the button this small piece of code gets executed<\/p>\n<p><code><br \/>\nSearch.getCustomers(searchField,searchValue,CustomerCallBackHandler);<br \/>\n<\/code><\/p>\n<p>When the javascript gets a response back, the CustomerCallBackHandler will be executed. That looks like this<\/p>\n<p><code><br \/>\nfunction CustomerCallBackHandler(data){<br \/>\n<\/code><\/p>\n<p>Where data is an array of Customer JSON objects. This means that in my java Customer object I have the getter\/setter getId(),getName(). In javascript I can simply do data[0].id and data[0].name.<\/p>\n<p>Now isn&#8217;t that nifty?! \ud83d\ude1b<\/p>\n<p>\/me like<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In one of my projects the user has to select a customer from a dropdown list. Problem is that the number of customers they have is much to big to prefill. So I used dwr to build a solution. The user has a dropdown from which he can choose the field he wants to query &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/blog.pczone.be\/?p=103\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;DWR&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"enabled":false},"version":2}},"categories":[4,5,12],"tags":[],"class_list":["post-103","post","type-post","status-publish","format-standard","hentry","category-informatics","category-java","category-web"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/s3U9nk-dwr","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/blog.pczone.be\/index.php?rest_route=\/wp\/v2\/posts\/103","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.pczone.be\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.pczone.be\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.pczone.be\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.pczone.be\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=103"}],"version-history":[{"count":0,"href":"https:\/\/blog.pczone.be\/index.php?rest_route=\/wp\/v2\/posts\/103\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.pczone.be\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=103"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.pczone.be\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=103"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.pczone.be\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=103"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}