How to validate an IP address with a regular expression in JSF2

To validate that a JSF2 input text field contains a valid IPv4 IP address use the following code:

<h:inputText id="inputBoxId" value="#{backingBean.field}" validatorMessage="IP address is not valid">
<f:validateRegex pattern="^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$" for="inputBoxId" />
</h:inputText>

The regular expression can also be used outisde of JSF2 of course.

Posted in JSF2, Software Engineering | Tagged , , | 1 Comment

JSF2 XHTML facelets comments appearing in output

Having jumped in at the deepend with JSF2 recently I noticed that adding comments to my facelets pages using the standard HTML commenting syntax:

<!-- comment here -->

actually results in the comment being sent as part of the output stream to the browser.

This is very annoying because I’ve generally put the comments in the xhtml for maintenance purposes so I don’t want anyone who views the source to see them; also they can actually be interpreted by JSF component libraries and add rendered output which you didn’t expect (such as extra rows in auto generated tables).

Thankfully JSF2 has a handy setting to stop comments being sent in the output stream. In your project web.xml file simply add the following to your web-app section:

<context-param>
<param-name>javax.faces.FACELETS_SKIP_COMMENTS</param-name>
<param-value>true</param-value>
</context-param>

Comments should no longer make it to the output stream.

Posted in JSF2, Software Engineering | Tagged , , , | 1 Comment

Java JVM Remote Debugging

To enable remote debugging of a java application pass the following options to the JVM:

-Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=9999

Where 9999 is the port than the remote debugger will connect to.

Setting “suspend” to “y” will suspend the VM until the remote debugger is attached – which can then resume the session.

I use Eclipse IDE for remote debugging; other IDEs are available.

Posted in Java, Software Engineering | Tagged , , | Leave a comment

JavaScript quirks documented

I find myself creating and making use of increasingly complex JavaScript code as part of my day to day work.

JavaScript is now the standard mechanism for client side data manipulation in most web-based applications and as such has become increasingly important for all software developers to understand. There are plenty of tutorials and documentation on the web, but one of the most useful resources I have come across is JavaScript Garden which documents a lot of the quirks and performance issues within the language.

I’d be very interested in any other useful JavaScript resources covering the more complex areas of the language so please leave a comment if you know of any.

Posted in Software Engineering | Tagged , , | Leave a comment

Facebook finally supports HTTPS

Facebook has added a new setting to it’s Security Options to allow users to connect using the secure and encrypted HTTPS protocol which encrypts the http traffic going over the wire. This is good news for Facebook users and will hopefully encourage more mainstream sites to enable HTTPS secure connections by default.

Using HTTPS ensures that snoopers can’t simply pick up plain text login credentials being transmitted over insecure connections (e.g. coffee shop wifi). The Firesheep firefox plugin demonstrates how easy it is to snoop on user credentials.

To enable HTTPS within facebook follow these steps:

  • Login to facebook
  • Go to your Account menu and select Account Settings
  • Click the “change” link on the “Account security” section
  • Check the “Secure browsing (https)” check-box

Facebook Security Settings

  • Hit save

Facebook will now attempt to serve your connections over HTTPS. Note that many applications will not support HTTPS and will push you back onto HTTP.

Posted in Computer Related, Internet | Tagged , , , , | Leave a comment

Eclipse problems in Ubuntu 9.10 Karmic Koala

Since upgrading to Ubuntu 9.10 I’ve noticed various issues with the Eclipse IDE which I use for the majority of my development work. The most annoying problem is an inability to click on Ok/Confirm buttons in pop up dialogs (although hitting enter on a highlighted button works as a short term workaround).

Some research shows that this is a bug in the version of eclipse I’m using (Version: 3.4.2) and the way that it uses GTK+ (see: https://bugs.launchpad.net/ubuntu/+source/gtk+2.0/+bug/442078 for the gory details).

The fix is simply to set an OS flag prior to running eclipse, this can be achieved by executing the following command in the terminal you use to launch eclipse:

export GDK_NATIVE_WINDOWS=1

a simple way to ensure this is always set in your environment is to add this line to your bashrc file (a configuration file run at the start of each user session).

To do this edit the file as follows:

  • In a terminal window run the command:
  • nano ~/.bashrc

  • Pgdown to the bottom of the file
  • Add the line:
  • export GDK_NATIVE_WINDOWS=1

  • Ctrl-X to exit the editor
  • Answer “Y” to save the changes
  • Hit enter to confirm

The next time you log in and start eclipse the dialogs should behave correctly.

Posted in Computer Related, Linux | Tagged , , , , | Leave a comment

Facebook chat on the Nokia N900

Facebook now uses the Jabber (XMPP) protocol for Facebook Chat – this means that any device/software which supports the Jabber protocol can connect to facebook chat.

The Nokia N900 supports the Jabber protocol out of the box as part of it’s instant messaging support, so the N900 can connect to Facebook chat seamlessly. Below are the steps I followed to enable Facebook Chat on my N900.

  • Go to the Nokia N900 Settings Menu
  • Select the “VoIP and IM accounts” option

Voip an Im accounts

  • Select New account
  • Select the Jabber protocol

Jabber

  • In the User Name field enter <facebookusername>@chat.facebook.com

e.g. joebloggs@chat.facebook.com

  • In the Password field enter your normal Facebook password

Account

  • Hit the “Sign In” button

That’s it, you should now be signed in to Facebook Chat.

You can see who’s online and start chats using the Conversations/IM widget.

Posted in N900 | Tagged , , , , , | Leave a comment

Howto add programs to Ubuntu main menus

On Ubuntu 9.10, using Gnome desktop:

System -> Preferences -> Main Menu

This will prevent the following tool, which allows you to choose which applications sit under which menus and also to add new applications to the menus.

menuedit

Posted in Computer Related, Linux | Tagged , , , | Leave a comment

Upgrading Ubuntu 9.04 to 9.10 gives blank screen

ubuntu

ubuntu upgrade

I recently got around to upgrading my development machines from Ubuntu 9.04 to 9.10, mainly because 9.04 is now end of life.

The upgrade itself went very smoothly – just a case of agreeing to all the defaults and letting the upgrade software do it’s thing.

Everything was going well until the install completed and I got invited to restart the machine to complete the install… “no problem” I think, this has been the smoothest upgrade ever.

The computer restarts, I see a simple Ubuntu logo on both screens and then…. nothing. Both screens go blank and that’s how they stay. I can’t even Ctrl-Alt-F1 to a terminal. After some thought I recall that I put some proprietary ATI drivers on the 9.04 install to drive the ATI graphics card I use for dual monitors – I guess they don’t play nicely with X in Ubuntu 9.10. The problem then is probably in the xconfig

So here’s the solution that worked for me (I know there are probably more elegant solutions):

  • Reboot the machine
  • Opt for recovery mode from the Grub menu
  • Choose “Drop to root shell with networking” from the recovery menu
  • Delete the X config file (sounds scarier than it is)
  • > sudo rm /etc/X11/xorg.conf
  • Reboot the machine
  • Hope for the best…

This got me back up and running, and there was need to download any extra drivers for 9.10; I simply used the System -> Preferences -> Display options to configure my monitors as I wanted them.

Calm has been restored to the Karmic Koala.

Posted in Computer Related, Linux | Tagged , , , | 3 Comments