Skip to content
Feb 14 10

Mobile Optimised Website W3C Link Checker

by peter

This post is about link checking your mobile optimised site to W3C standard.W3C are a standards body who provides free link checking software, which can be run from their website. Link checking is a great way of improving a site’s quality and it can be done automatically! But where’s the support for mobile? I found it hard to run any link checkers whilst developing our mobile optimized site, so I tweaked the existing W3C link checker…

W3C Link Checker for Mobile

Finding no mobile link checkers I extended the W3C link checker to do the job. For security reasons you should go to the official site and alter the Perl script manually, but for the trusting the edited script can be downloaded here (I’ve also removed the 1 page per second limit).

To extend checklink for mobile user agents, add a new line to line 1307 of the checklink code containing:

$request->header('User-Agent', 'Mobile');

To run this link checker across your entire site you’ll need to run it recursively (using -r), I run the script using (For -S0 to work you’ll need to alter the script again):

checklink-m -Hbrq -S0 http://stripeylines.com > release-12.2.m.html

Future Work

Ideally, the checklink script would be extended and the user-agent passes as a parameter (permitting both PC and mobile site checking). If anyone wishes to take this further I’d be interested in the end result. If I have no responses in the following weeks I’ll contact W3C with my suggestions.

Feb 3 10

iPhone Web Development using Spring Web MVC

by peter

This post builds on last week’s post about how to polish your mobile optimized website to work best with the iPhone. This week I’ll talk about mobile web development using the Spring Web Framework. I’ve been using the Spring Framework to integrate most of my code base and I was interested in how Spring Web Framework would work with a mobile optimized site. As the Spring Web Framework is mostly back-end I didn’t really expect any front-end integration issues….

Spring Web

Spring Web MVC provides a Web framework around the Model-View-Controller paradigm. As we see with the workflow picture below this paradigm neatly integrates your presentation level (the View) with your business logic (the Controller) written in Java and XML.

Picture describing an incoming Request workflow in Spring Web MVC

Incoming Request workflow in Spring Web MVC (courtesy of http://static.springsource.org)

If this diagram looks intimidating you might want to check out the Spring Web Framework documentation.

Spring Web for Mobile

Most major websites need some form of mobile optimization. Here we talk about the specific changes to Spring Web to develop our iPhone app’s website: StripeyLines. These changes are split into three main sections:

  1. Structuring our mobile optimized site – We wanted our website for StripeyLines to show one set of HTML pages for our mobile users and another set for our non-mobile (err PC?) users.
  2. Detecting mobile browsers – We wanted to neatly structure how the browsers user-agent was detected.
  3. Using mobile optimized forms – We wanted to have mobile optimized forms in the style of my previous post.

Structuring our mobile optimized site

Ideally, to make a website for multiple devices we would have the same HTML for both browser types and swapped HTML – but the defacto mobile web standards set by Apply forbid this. Instead we have mirrored content across both mobile optimized and our PC website. This was organised using a strict naming convention:  all our PC pages ended in .jsp all the corresponding mobile pages ended in -m.jsp - which is manageable for our size project. If anyone has a different preferred style you can add to the discussion below.

Detecting mobile browsers

Having neatly structured out the HTML content into PC and mobile files all we needed was to direct the user to their corresponding page. We followed the Spring Web standard and made all our public URL’s end in .htm which then resolved to a JSP page ending in .jsp or -m.jsp.

Implementing this involved extending the standard Spring Web workflow to intercept incoming requests, notably the SimpleUrlHandlerMapping, which can be found in your Spring <servlet-name>-servlet.xml file. Here is ours below:

<!--
This bean maps URL requests to controllers.
-->
<bean id="handlerMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<!--
  This interceptor catches all requests and redirects them to portal or mobile html content.
-->
<property name="interceptors">
   <list>
     <ref bean="MultiViewController"/>
   </list>
</property>

<!--
   Catch all .htm requests and use a simple controller to present them
-->
<property name="mappings">
  <props>
    <prop key="/*.htm">ForwardViewController</prop>
  </props>
</property>

</bean>

There are two beans we reference in the exert above: the MultiViewController, which intercepts each incoming request, and the ForwardViewController which handles incoming requests ending in .htm. Whilst the ForwardViewController does nothing, the MultiViewController integrates with Spring by extending the Interceptor interface as shown below.

/**
 * This Interceptor decides whether to present mobile or PC html content.
 */
public class MultiViewController extends HandlerInterceptorAdapter {

This class overrides the postHandle method to additionally:

  1. Detect the user-agent
  2. Alter the incoming request to either -m.jsp or .jsp
  3. Handle requests of unknown pages

Spring Web Forms

Spring Forms are a nice feature of the Spring Web Framework. Spring Forms simplifies Web Development for Java Developers by abstracting HTML forms to Java Objects. For example, the follow snippet in my JSP:

<form:form>
     First Name:<form:input path="firstName" />

would automatically populate the attribute ‘firstName’ of a Java Object when submitted.For those fearful of frameworks, the JSP is compiled to this familiar HTML:

<input type="text" value="" name="userEmail" id="userEmail">

Note the type of “text” is assumed by the Spring Integration.

Spring Web Forms for iPhone

Last week, we optimized HTML forms for the iPhone. This optimization required un-standard HTML but surprise surprise Spring Forms only generate standard HTML. Spring Form’s inputs have the standard HTML types: input, select – they do not have an ‘email’ type. Any tinkering is blocked at compile time by Spring’s Form Tag library definition.
I’ve thought of recommending this extension to future Spring Web implementations but I wouldn’t want to encourage un-standard approaches to web development – have readers any views on the matter?

In the end, I opted for a Javascript solution to change the HTML dynamically when the page is loaded.

So, I defined a Javascript function to convert the input element

/**
 * This javascript is a workaround for presenting mobile safari tags using spring MVC.
 */

/**
 * This function takes an element id and converts it to an email input, removing
 * apple's auto correct / capitalise.
 *
 * @param elementId
 *            the HTML text input into an email input for iPhone optimization
 */
function convertToEmailInput(elementId) {
	document.getElementById(elementId).type = 'email';
	document.getElementById(elementId).setAttribute('autocapitalize', 'off');
	document.getElementById(elementId).setAttribute('autocorrect', 'off');
}

On page load I call the Javascript function with its reference to convert any HTML input fields. The following HTML snippet converts the userEmail input introduced above:

<body onload="convertToEmailInput('userEmail');">

I swallow a bit of pride in posting this, but if anyone has anything to contribute to this page please comment. When I was developing this solution I couldn’t find any Web resources to my aid! In the following weeks I’ll contact the Spring Web team and ask for some mobile extensions – if you have any thoughts on the matter leave a comment.

Jan 26 10

iPhone Web Development Tips and Tricks

by peter

This post is all about how to polish your mobile optimized website to work best with the iPhone. Mobile is taking off: it’s now just a little bit more convenient to pick up your phone for something, then to go and sit in front of a computer. That said, mobile is still extremely inconvenient – mobile and web developers can make this easier and that’s the point of this post: a more polished site means higher conversion. Making mobile more convenient is what I’m currently working on as a day job, see the Stripeylines iPhone app.

Whilst developing the mobile optimized version for our iPhone app, StripeyLines, I discovered that our site (such as our login page) needed some tweaking. These were:

  1. Stopping auto capitalision on some text input fields (such as usernames)
  2. Selecting a suitable keyboard

Autocapitalisation

Auto-capitalisation is supposedly to help users using Apple’s mobile Safari. You don’t want this on any case sensitive fields like: username, userId. To remove apply propriety html to each tag:
<input autocorrect="off"
autocapitalize="off" class="text-field" type="email" name="j_username"
value="">

Nasty eh? It doesn’t appear like this Apple plan to standardise this method. It’s a presentation level, mobile specific style – why isn’t this in CSS? For mobile CSS Apple are following the standards route – why not on this? All their new mobile specific CSS (those ones starting with -webkit) are typically being proposed for future CSS versions.

For more info, on these tags and form designing, see Apple Dev Docs.

Selecting Keyboards

We all know user-names which are email addresses are a good idea (except affiliatewindow.com – shame!). To show an email keyboard, more custom HTML is required. This time Apple has extended the input type to contain the ‘email’ field.

<input type="email" />

To select other keyboards see the Apple Coding How to – documentation, anyone?

Integrating these into the Spring Web Framework

Next week, I’ll take you on the adventure of integrating these tags into the Spring Web Framework.

Jan 4 09

UK Social Trends

by peter

The following post highlights some of the more interesting tables from the UK National Statistics report on Social Trends.

This post is split into the following categories:

Equality and Inequality

Girls are better than boys at Maths and Science

Table 3.12 Pupils reaching or exceeding expected standards through teacher assessment: by Key Stage and sex (page 38 )

At all ages males commit more crimes than females.

Crimes committed by age and gender

Figure 9.12 Offenders as a percentage of the population: by sex and age, 2006 (page 129)

Social Myths

Only 42% of Burglaries result in loss

Also, only 57% of burglaries involve entry.
Table 9.3 Domestic burglary: by type (page 124)

Only 29% of phone thefts happen when carried by its owner

Figure 9.4 Mobile phone theft: by circumstance of how the phone was stolen, 2005/06 (page 124)

Young girls are more promiscuous then young men (16-19)

No. of sexual partners by gender (16-19 years)

No. of sexual partners by gender (16-19 years)

Table 7.19 Number of sexual partners in the previous year: by sex and age, 2006/07 (page 104)

More new HIV diagnosis is due to heterosexual sex

Nearly double the amount of new HIV diagnosis were the result of heterosexual sex, than homosexual sex; also Heterosexual sex caused 25 times more infections than injecting drug use. Note, this is per thousand and not a percentage of each group.

New Diagnosis of HIV

New Diagnosis of HIV

Figure 7.22 New HIV diagnoses: by year and route of transmission (page 106)

Only half of people summoned actually serve Jury duty

Table 9.21 Jury summons for Crown and Civil Courts (page 134)

Safer to be a cyclist than a pedestrian

Cycling is the third most lethal form of transport, after walking and motorcycling.
Table 12.18 Passenger death rates: by mode of transport (page 173)

read more…