Best Practice

CMS Integration

...

Deep Linking

In order to integrate deep linking in your wingS application you can use an SRequestListener. Assuming that your wingS session should look for a parameter named id and call a class method named loadId if the parameter exists and represents an int the code handling a URL similar to http://example.com/?id=23 could look like this:

import org.wings.event.SRequestEvent;
import org.wings.event.SRequestListener;
import org.wings.session.SessionManager;

SessionManager.getSession().addRequestListener(new SRequestListener() {
  public void processRequest(SRequestEvent re) {
    if (re.getType() == SRequestEvent.DISPATCH_START)
      if (SessionManager.getSession().getServletRequest().getParameter("id") != null) {
        try {
          int idNo = Integer.parseInt(SessionManager.getSession().getServletRequest().getParameter("id"));
          loadId(idNo);
        } catch (NumberFormatException ex) { }
      }        
    }
  });

It is important to know that changing the session state is allowed in the event dispatching phase only, in the above example if (re.getType() == SRequestEvent.DISPATCH_START) makes sure that we're in the right session state.

--Szymon Polom 04-Dec-2007 23:05 CET