Note: see newer samples for Portlet Factory version 7.0
The attached sample shows how the client browser device type can be used with a profile selection handler, so that for different browser types you will get a different Portlet Factory profile. With this technique, you can create a single model that has two profiles: one for desktop browser and another for small mobile devices. The assumption is that HTML is supported for the mobile device (which it is for many devices including Blackberry).
The profile selection handler is defined in these two files:
WEB-INF/config/selection_handlers/devicetype_handler.xml - This defines the profile selection handler properties.
WEB-INF/work/source/com/bowstreet/samples/deviceprofile/DeviceTypeSelectionHandler.java - The Java class for the selection handler.
The Java code for the selection handler currently looks at the "User-Agent" header from the request and checks if it contains the string specified as the "MobileUserAgentString" in the profile handler XML file. NOTE: also, the code is currently hard-coded to set the profile to "Mobile" if the User-Agent contains "Firefox". This was just to test the mechanism of device profiling and should be removed. (With the current test code, running in IE gives "Browser" profile while running in Firefox gives "Mobile" profile.)
The custom selection handler is used by the ClientDeviceType profile set. There are two profiles in that profile set, "Browser" (for desktop browser) and "Mobile". That profile set is used to profile two values in the sample model:
- A Data Column Modifier that hides most columns is enabled only for "Mobile" profile.
- The number of rows per page is set to "4" for "Mobile" profile.
A couple notes about making edits to the files used by the profile selection handler:
- The profile selection handler XML file (devicetype_handler.xml) isn't dynamically reloaded until the whole WAR is reloaded, so any changes you make to the Properties in that file won't take effect until the WAR is reloaded.
- The profile selection handler Java class is dynamically reloaded. You can just regen and save the model, then logout/login to see changes to this file.
Here is a screenshot of the running sample model with the "Browser" profile, in Internet Explorer.
Here is a screenshot of the running sample model with the "Mobile" profile in Firefox.
Notes on running the sample and prerequisites
Import the attached zip file into your project using the Import WebSphere Portlet Factory Archive command.
The sample model uses data from the Tutorials and Samples / Applications feature set, so that feature set must be installed in the project.