Monday, May 11, 2009

Ghosts in the browser

It's not a bug - it's a feature

Did you know that you're not where you are? I mean virtually of course. Confused? Read on...

Let's have a simple example: 2 simple views (or pages or however you'd like to call them). One that asks for your name and the other one that says that you're the master and this kind of things. A simple "Hello, world!" application. Nothing fancy.

Now let's assume the obvious which is: you're writing it using Java Server Faces. It's good for everything so why shouldn't it be good for a Hello, world! application?

So we have it, one edit (h:inputText, for whatever reason) and a button (h:commandButton, again like it couldn't be simply a button... nevermind) and we have the next page that shows your name with a nice greeting (using h:outputText for whatever reason, like text nodes were smelly or something... nevermind). Of course we have all the necessary bits and pieces there: a bean with sayHello method, navigation cases set up properly, all the entries in web.xml are there - we're good to go!

Now let's run our glorious application.

1. We're at the start page that kindly asks us to enter our name into the box. Well, we're not that open to mind control so we enter something like "Harry Potter" and click the fancy button that's on the same page.
2. Now we're on another page, this time it's the page saying, that "Harry Potter is most welcome" and "that you can click the back link to get back".

But wait! Have you noticed the address bar? Whatta heck?! It is still pointing to the page where we've had the opportunity to enter our name. We think "something is seriously wrong with our application". But in fact it's not our application that's wrong - it's just how JSF works.

It's not a bug - it's a feature :D And you can't do anything with it. Get over it! Don't look at the address bar - there's nothing of interest to you.

No comments:

Post a Comment