{"id":829,"date":"2006-08-01T01:52:06","date_gmt":"2006-08-01T05:52:06","guid":{"rendered":"http:\/\/cephas.net\/blog\/2006\/08\/01\/webwork-and-meaningful-urls\/"},"modified":"2006-08-08T12:52:19","modified_gmt":"2006-08-08T20:52:19","slug":"webwork-and-meaningful-urls","status":"publish","type":"post","link":"https:\/\/cephas.net\/blog\/2006\/08\/01\/webwork-and-meaningful-urls\/","title":{"rendered":"WebWork and meaningful URLs"},"content":{"rendered":"<p>Personal pet peeve: <a href=\"http:\/\/www.google.com\/search?q=meaningful+urls&amp;start=0&amp;ie=utf-8&amp;oe=utf-8&amp;client=firefox-a&amp;rls=org.mozilla:en-US:official\">meaningful URLs<\/a> (which tonight I found out go by many names: <a href=\"http:\/\/www.google.com\/search?q=pretty+urls&amp;start=0&amp;ie=utf-8&amp;oe=utf-8&amp;client=firefox-a&amp;rls=org.mozilla:en-US:official\">pretty URLs<\/a>, <a href=\"http:\/\/www.google.com\/search?q=restian+urls&amp;start=0&amp;ie=utf-8&amp;oe=utf-8&amp;client=firefox-a&amp;rls=org.mozilla:en-US:official\">RESTian URLs<\/a>, <a href=\"http:\/\/www.google.com\/search?q=ses+urls&amp;start=0&amp;ie=utf-8&amp;oe=utf-8&amp;client=firefox-a&amp;rls=org.mozilla:en-US:official\">SES URLs<\/a>, <a href=\"http:\/\/www.google.com\/search?q=hackable+urls&amp;start=0&amp;ie=utf-8&amp;oe=utf-8&amp;client=firefox-a&amp;rls=org.mozilla:en-US:official\">hackable URLs<\/a>, etc&#8230;).  At <a href=\"http:\/\/jivesoftware.com\/\">work<\/a>, we use <a href=\"http:\/\/www.opensymphony.com\/webwork\/\">WebWork<\/a> extensively but up until this point we haven&#8217;t made an effort to create meaningful URL&#8217;s.  As with any well designed framework, it turns out that there are a couple of ways you can create meaningful URL&#8217;s, with different levels of meaningfulness.  <\/p>\n<p>Version 2.2 of WebWork introduced the <a href=\"http:\/\/www.opensymphony.com\/webwork\/api\/com\/opensymphony\/webwork\/dispatcher\/mapper\/ActionMapper.html\">ActionMapper<\/a> interface and a class called <a href=\"http:\/\/www.opensymphony.com\/webwork\/api\/com\/opensymphony\/webwork\/dispatcher\/mapper\/RestfulActionMapper.html\">RestfulActionMapper<\/a>, which gives you the ability to create URLs that might look something like this:<br \/>\n<code><br \/>\nhttp:\/\/bookstore.com\/books\/category\/java\/keyword\/webwork<br \/>\n<\/code><br \/>\ninstead of the more common:<br \/>\n<code><br \/>\nhttp:\/\/bookstore.com\/books.jspa?category=java&keyword=webwork<br \/>\n<\/code><br \/>\nThe nice thing about the RestfulActionMapper implementation is that you don&#8217;t have to write any code to parse the URL: you set up your WebWork actions with the appropriate setters and the RestfulActionMapper handles the rest.  The downside is that this still isn&#8217;t really a truly hackable URL. For example, although this URL:<br \/>\n<code><br \/>\nhttp:\/\/bookstore.com\/books\/category\/java\/keyword<br \/>\n<\/code><br \/>\nand this URL:<br \/>\n<code><br \/>\nhttp:\/\/bookstore.com\/books\/category<br \/>\n<\/code><br \/>\nwould probably work, they don&#8217;t really make sense. Why are &#8216;keyword&#8217; and &#8216;category&#8217; hanging around at the end?  Both of the words are extra information required by the implementation that don&#8217;t add any value to the user. <\/p>\n<p>The second way you can create meaningful URLs is by creating your own ActionMapper. You can get a good start by checking out the source code for the <a href=\"http:\/\/www.opensymphony.com\/webwork\/api\/com\/opensymphony\/webwork\/dispatcher\/mapper\/DefaultActionMapper.html\">DefaultActionMapper<\/a> and the RestfulActionMapper. To set properties on your action instances, you&#8217;ll want to create a <a href=\"http:\/\/java.sun.com\/j2se\/1.5.0\/docs\/api\/java\/util\/HashMap.html\">HashMap,<\/a>, add the appropriate properties from your URL to the map and then either create and return a new <a href=\"http:\/\/www.opensymphony.com\/webwork\/api\/com\/opensymphony\/webwork\/dispatcher\/mapper\/ActionMapping.html\">ActionMapping<\/a> using the action name and map or call the <a href=\"http:\/\/www.opensymphony.com\/webwork\/api\/com\/opensymphony\/webwork\/dispatcher\/mapper\/ActionMapping.html#setParams(java.util.Map)\">setParams() method<\/a> on an existing mapping. The end result is that you should be able to create and use meaningful URL that looks like this:<br \/>\n<code><br \/>\nhttp:\/\/bookstore.com\/books\/java\/webwork<br \/>\n<\/code><br \/>\nAlso of note:<\/p>\n<ul>\n<li><a href=\"http:\/\/www.adaptivepath.com\/publications\/essays\/archives\/000058.php\">User-Centered URL Design<\/a><\/li>\n<li><a href=\"http:\/\/www.useit.com\/alertbox\/990321.html\">URL as UI<\/a><\/li>\n<li><a href=\"http:\/\/radio.weblogs.com\/0115489\/categories\/movingForward\/2002\/12\/20.html#a45\">What is interesting about LibraryLink<\/a><\/li>\n<li><a href=\"http:\/\/en.wikipedia.org\/wiki\/Representational_State_Transfer\">Representational State Transfer<\/a><\/li>\n<li><a href=\"http:\/\/www.w3.org\/Provider\/Style\/URI.html\">Cool URIs don&#8217;t change<\/a><\/li>\n<li><font color=\"red\">Updated 8\/1\/2006: Great quote by <a href=\"http:\/\/en.wikipedia.org\/wiki\/David_Gelernter\">David Gelernter<\/a> via <a href=\"http:\/\/www.dehora.net\/journal\/2006\/07\/18fd0fefe7bbea0f77a443cfd95f9554_1.html\">Bill Dehora<\/a>: &#8220;If you have three pet dogs, give them names. If you have 10000 head of cattle, don&#8217;t bother.&#8221;<\/font><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Personal pet peeve: meaningful URLs (which tonight I found out go by many names: pretty URLs, RESTian URLs, SES URLs, hackable URLs, etc&#8230;). At work, we use WebWork extensively but up until this point we haven&#8217;t made an effort to create meaningful URL&#8217;s. As with any well designed framework, it turns out that there are &hellip; <a href=\"https:\/\/cephas.net\/blog\/2006\/08\/01\/webwork-and-meaningful-urls\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">WebWork and meaningful URLs<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[5,13,4,30],"tags":[],"_links":{"self":[{"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/posts\/829"}],"collection":[{"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/comments?post=829"}],"version-history":[{"count":0,"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/posts\/829\/revisions"}],"wp:attachment":[{"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/media?parent=829"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/categories?post=829"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/tags?post=829"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}