NetBeans Visual Web Pack - Real World Apps Tip #4 - "Pretty" URLs

Problem


One issue that's been plaguing the NetBeans Plugin Portal from the beginning is the lack of direct URLs to portions of the web application.  As many of you know, JSF page navigation creates some pretty horrendous URLs.  Besides being "Ugly", as one user put it, you can't use the URLs to reference pages in the web application.  Without going into the design considerations for JSF, I will mention that one of the main issues is state.  Yes I know.  In any web application development managing state is always an issue.  If you read my JavaOne 2007 BOF slides, you will see that I had somewhat of a solution on slides 54-55 by providing a "Permanent Link" then dispatching through my main page.  This worked but when you ended up on the page, the URL was still ugly.  I've Googled many times on the subject but always seem to wind up in the same place with the solution.  Winston Prakash in the NetBeans visual web engineering group did a blog entry on another real world application built on Visual Web Pack.  A few weeks ago I was looking at what Joshua van Aalst had done with his web site.  Joshua had a goal of making much of the web site Search Engine Optimized (SEO) so he needed to replace the ugly URLs.  His technique included using a servlet filter and converters.  In looking at his solution and doing some testing, I realized that my original solution was very close with one critical mistake.  I was sending everything through the main page then doing a redirect to the PluginDetailPage after setting up state.  

Solution

The solution - change all the links in the web app to point to the real pages and set up the state in each page "init()" method.  The solution involves still using "GET" style URLs.  So the first step is to design the URL for each page that you will provide direct linking to.  The URL will need to contain adequate information for the given page to build the web application state on the fly.  For example, to provide direct linking to the category list page, I designed the following URL.

http://plugins.netbeans.org/PluginPortal/faces/CategoryPage.jsp?categoryname=Tools

As you can see, the URL has a parameter named  "categoryname" and a value of "Tools".  In the "init" method of the CategoryPage class,  I use the following code.

        /\*\*
\* Process a GET type request.
\*/
HttpServletRequest request = (HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();
String [] categories = request.getParameterValues("categoryname");
if(null != categories && categories.length == 1) {
getSessionBean1().setCurrentCategoryName(categories[0]);
}


The above code is what the Plugin Portal needs to set up state for the category list page.  That's all that's really needed.  The major refactoring I had to do was to change all the hyperlinks to be in this "Pretty" format.

Comments:

Post a Comment:
  • HTML Syntax: NOT allowed
About

David Botterill

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today