The two main components that enable the share-app mode are SessionLocal and URLLocal because they are values that are external to a particular instance of the swingweb application. Below are the descriptions on the components.

SessionLocal

A SessionLocal is an object referencing a value in swingweb session. The implementation detail of accessing swingweb session is encapsulated inside SessionLocal so the developer does not need to know how it is done. The session local can be declared anywhere in the application - be it in a component, in the business class, etc. One of the uses of SessionLocal is to implement share-app mode components. For example, to implement a JLabel that display different text set to each user, you can do the following

public class SharedJLabel extends JLabel
{
  private SessionLocal _text;

  public SharedJLabel(String text)
  {
    super(text); //nothing special since constructor uses setText
  }

  private synchronized SessionLocal _getTextLocal()
  {
    if (_text == null)
    {
      _text = new SessionLocal();
    }
    return _text;
  }

  public void setText(String text)
  {
    _getTextLocal().setValue(text);
    super.setText(text);
  }

  public String getText()
  {
    return (String) _getTextLocal().getValue();
  }
}
  


Now for application development, just substitute the use of JLabel with the SharedJLabel and the user would be able to see the component reflecting a text string in their session. For example, if the component is used to display the corresponeding REMOTE_ADDR of the client browser as the user connect to the website, each user will see that their own IP being displayed in the component.

Note that the modification does not change the api of JLabel component in anyway. That is the beauty of it. Also, the component will work in normal Desktop mode as swing application too, since the SessionLocal will be just a place holder for a text value. We could also use the same technique to make the icon of the text, color of the text even TreeModel to make the component we need become shareapp-mode enabled.

URLLocal

URLLocal is a way for swingweb to support URL manipulation/customization and bookmarkable URL to a swingweb (share-app mode) application. The two main uses of URLLocal are:

  • To allow different view of your application for different user because of URL
  • To support bookmarkable section of your application
Similar to SessionLocal, a URLLocal is an object referencing to some external value - except that this value is from the URL. Furthermore, an URLLocal object is named and could have a default value. The code section below shows you how to use URLLocal
  ... somewhere in your code ....
  URLLocal section = new URLLocal("section", "sect1", true); //name="section", default="sect1", alwaysShow=true
  SwingWebUtils.registerURLLocal(section);  
All the code does is to register a url local to the swingweb system so the "section=sect1" will show up in the URL. The effect of the code is when the swingweb application run in browser, the "section=sect1" will show up in the URL of the browser.

The value of the URLLocal (hence the value of section in the browser URL) can subsequently be changed by the:
  • Your application code (e.g. section.setValue("sect2")).
  • The link from the application in user browser.