Hi Bruno,

please open a jira feature/improvement request. I'll have a look. Thanks.

-Juergen

On Thu, Jun 16, 2011 at 10:20 PM, Bruno Borges <[email protected]> wrote:
> I came once with this but I don't remember what happend.
>
> Anyway, I want to share the idea with you again:
>
> We are building mobile web apps and a common scenario that came to us is
> that mobile web applications often must have specific styles per devices.
>
> We have a MobileFilter configured in the web.xml to intercept the request
> and identify the device, adding the device's name/type/other info to the
> user's session.
>
> When the Wicket Session is created, we get the device name and set it as a
> style, like "android", "iphone" or "blackberry".
>
> But the application has tons of HTMLs which are already for desktop browser
> access.
>
> So here is what I'm are thinking about:
>
> Say there's a HomePage:
> - HomePage.html
> - HomePage_android.html
> - HomePage_iphone.html
> - HomePage_blackberry.html
>
> If a desktop user comes in, HomePage.html is rendered. If an Android user
> comes in, HomePage_android.html loads fine.
>
> The problem is that we often don't have to code specific versions per
> device. Some pages can have a more generic "mobile" version, like rendering
> a list with <li> instead of <table>.
>
> But there's no fallback style.
>
> So what we want is that this scenario could work:
>
> - ListItems.html (desktop version)
> - ListItems_android.html (android's specific version)
> - ListItems_mobile.html (any other mobile devie)
>
> If a user from blackberry/iphone/nokia or anything comes in, and based on
> rules we identify him as a mobile device, we set the fallback style as to
> "mobile" and the specific style as "his_device".
>
> I've come with a ResourceStreamLocator that does this, but not using styles.
> The streamLocator does not accept a list of styles to test, but it accepts a
> list of extensions.
>
> So what I did was to have HTML files like such:
> Page[.device].html (with dot instead of underscore).
>
> The whole variation/style/locale would still work without any problem.
>
> ## Here is the code:
>
> package com.myproject;
>
> import java.util.Locale;
>
> import org.apache.wicket.Session;
> import org.apache.wicket.util.resource.IResourceStream;
> import org.apache.wicket.util.resource.locator.IResourceStreamLocator;
> import org.apache.wicket.util.resource.locator.ResourceStreamLocator;
>
> import com.myproject.Device;
>
> /**
>  * @author Bruno Borges
>  */
> public class MobileStreamLocator extends ResourceStreamLocator implements
> IResourceStreamLocator {
>
> @Override
> public IResourceStream locate(final Class<?> clazz, String path, final
> String style, final Locale locale,
> final String extension) {
>
> StringBuilder newExtensions = new StringBuilder();
> newExtensions.append(extension);
>
> if ("html".equals(extension) && Session.get() instanceof
> MobileWicketSession) {
> MobileWicketSession ms = (MobileWicketSession) Session.get();
> Device device = ms.getDevice();
> if (device.isMobile()) {
> newExtensions = new StringBuilder();
>
> // add specific device name
> newExtensions.append(device.getDeviceType()).append(".").append(extension).append(",");
>
> // add generic mobile extension
> newExtensions.append("m.").append(extension).append(",");
> newExtensions.append(extension);
> }
> }
>
> return super.locate(clazz, path, style, locale, newExtensions.toString());
> }
> }
>
> *Bruno Borges*
> www.brunoborges.com.br
> +55 21 76727099
>

Reply via email to