jump to navigation

JSF, Float, and f:convertNumber February 16, 2010

Posted by Phill in Frameworks, Presentation Layer.
Tags: , , ,
comments closed

I’ve been having some fun issues with JSF and converting Float issues. Essentially the problem occured when converting a primitive float type to a java.lang.Float type in my value object (I was trying to updating a float value from an inputText field). I kept getting errors like:

java.lang.IllegalArgumentException: argument type mismatch

Anyway, I found an answer which seems to work, but rather than post it directly here I’ll simply link to the original question on StackOverflow (in case someone posts a better answer subsequently!).

These kind of issues are one of the many reasons why JSF has gone down in my estimation… it’s not a bad framework, it just seems to make what should be simple things massively complicated! That said, JSF 2.0 looks good, so maybe it will solve these kind of issues.


Wicket September 17, 2009

Posted by Phill in Frameworks, General J2EE, Presentation Layer.
Tags: ,
comments closed

The past few days I’ve been prototyping for a new project we’re starting up at work. Previous web projects we’ve done have mainly been using JSF, however for this project I’ve been looking into Apache Wicket.

My first impressions are, I like it. I like it a lot, in fact. It seems to achieve a much more clean separation between code / components and HTML than other frameworks do. It does take a while to get your head around it though – I’ve only been working with it for a few days so am still finding my way round!

But I expect I will blog up some info when I’ve got my head around it.

Another JSF Gotcha July 9, 2008

Posted by Phill in General J2EE.
Tags: , , , ,
comments closed

JSF has a number of “gotchas”. Today I managed to stumble across another one. Again.

Suppose you’re designing a user administration panel, and you want to be able to edit a user and select a list of roles for them. You’d think a fairly logical control to use would be a selectManyListbox (assuming, for the moment, it’s a fairly small number of roles).

So, in your backing bean you add in a List containing all the user roles, and you configure your SelectItems and converters. Except you still keep getting that damn error message: “Validation Error: Value is not valid”.

It turns out the problem is that JSF is so advanced, it can’t yet handle the Java Collections Framework: you have to use arrays instead. That’s right, in your backing bean, if you use List<MyClass> as the value binding for the list box, it will not work. You need to use MyClass[] instead.

I am using an older version of JSF (1.1 as opposed to 1.2) so that might be fixed now – still rather annoying to come across it though.

More on JSF and Spring Integration: MessageSources June 18, 2008

Posted by Phill in Frameworks.
Tags: , , ,
comments closed

A couple of days ago I wanted to move my application messages file out of the classpath into WEB-INF for some reason which I can’t actually remember now. Anyway, Spring definitely supports loading message files from WEB-INF, but I don’t think JSF does (I think it loads resources from the classpath).

Plus, it makes sense to have all messages loaded from the one MessageSource – that way, if I add another messages file, the configuration will only need to be changed in one place.

After a bit of Googling, I managed to get it to work. If you want to have JSF using a Spring MessageSource, you will need to use the following class: MessageSourcePropertyResolver. Copy and paste that into your codebase somewhere. Then, edit your faces-config.xml file and add in the appropriate element:


Then, you can use the MessageSource in your JSF pages like this:#{messageSourceBeanName[‘message.key’]}

Tip: I don’t like typing out “messageSource” every time I want to use a message in a JSF page – I always used the shorter “msg” before. You can do this with Spring – just alias your MessageSource bean with the name “msg”. For example,

<alias name=”messageSource” alias=”msg” />

JSF Custom Components with Facelets and IceFaces June 3, 2008

Posted by Phill in General J2EE.
Tags: , , , ,
comments closed

I was having fun earlier trying to get a custom component working. I wanted to create a dynamic menu component, which I didn’t think was easily possible with standard JSF components.

What I wanted rendered was something like this:

<div class="navbar">
    <li class="selected"><a href="#">commandLink</a></li>
    <li><a href="#">commandLink</a></li>

Fairly simple, wouldn’t you think?

Well, actually it’s not that difficult – once you know how!

The problem comes with the way child components are rendered. I was creating a new HtmlCommandLink in my custom component, and then using encodeBegin(context) and encodeEnd(context) to render them.

However, I found that when you clicked on the links, nothing would happen! I looked at the source code, and couldn’t actually see anything wrong. It all looked fine… my only thought was that somehow IceFaces wasn’t picking up the components if I rendered them directly.

One idea was to actually add the commandLinks to the list of children, i.e. getChildren().add(commandLink). However, this doesn’t render components in the way that you want – i.e., I wanted all of the links surrounded by <li> and </li>!

In the end, what I did was create another custom component (ListElementComponent), and have it render an “<li>” and “</li>” in the encodeBegin(…) and encodeEnd(…) methods respectively. Then, I added the commandLink as a child of the ListElementComponent, and added the ListElementComponent as a child of my custom component.

Clear? Probably not!

Basically, the logic was as following:

for (each menu item) {
link = createCommandLink();
listElement = new ListElementComponent();

This seemed to force JSF / IceFaces to render the HTML as I wanted it.

I don’t know if there was an easier way of doing it, but unfortunately the documentation on custom components in JSF isn’t exactly brilliant!

JSF Issues May 14, 2008

Posted by Phill in Frameworks.
Tags: , ,
comments closed

The project I’m currently working on is using JSF and IceFaces. It’s been a while since I used JSF, and I’d forgotten just how annoying it can be at times. The problem is always using frameworks that write the HTML for you: if you don’t have so much control over what is actually output to the browser, if you have a problem (which you inevitably will) fixing it will not be a simple matter.

Take today, for example. I wanted to include a custom JavaScript on an IceFaces page. Simple enough, you would think. Unfortunately, I had a problem where it would only work once you’d refreshed the page! Bizarrely, Firebug showed the JavaScript as existing in the JavaScript body – but it didn’t seem to actually be loaded by the browser.

I think this might be a problem with the way IceFaces loads things up using AJAX, but either way i’m none too impressed. The solution for the time being is to actually use a <redirect/> tag in my faces-config.xml (as suggested on this thread), this isn’t an ideal solution but it seems to work for the moment.

Although JSF does make some development quicker, the amount of time you lose to stupid problems like this probably negates any gains you made originally.

For the next web based project I do, I think I will try something like Spring WebFlow or Wicket, which both look like very interesting frameworks and don’t suffer from the same issues as JSF (although undoubtedly they have their own issues!)

JSF Backing Beans and Spring May 2, 2008

Posted by Phill in General J2EE.
Tags: , ,
comments closed

In the Spring Documentation about JSF integration, the DelegatingVariableResolver (and a few alternatives) are explained. There is one thing it doesn’t mention explicitly, though, which is using Spring managed beans as backing beans.

As it happens, it’s fairly easy: you just need to use beans with request or session scope. There is a little bit of configuration needed for this, but you get the great benefits of having all your bean definitions in one place, as well as all the benefits of Spring managed beans and configuration!

Provided that you have the DelegatingVariableResolver (or one of the equivalents) set up, you can then use
your Spring managed beans in exactly the same way as you would use JSF managed beans.

JSF and IceFaces April 4, 2008

Posted by Phill in Frameworks.
Tags: , ,
comments closed

I mentioned a couple of posts ago that I was trying out Google Web Toolkit. Well, I’ve come to the conclusion that Google Web Toolkit is not the right solution for this particular project.

The problem was mainly one of scope: I think GWT, due to the way it’s designed, is more for small-to-medium size projects at the moment. The project which I am currently working on is small at the moment, but we will need to integrate various other things with it in the future and it will grow.

I did look at Echo2 as well (thanks to Dalibor for pointing it out to me), and that does look good – more like it would be able to handle larger applications, due to the way the page is loaded – but I don’t think it’s exactly what we need at the moment either.

What we have done is use JSF with IceFaces. IceFaces is a “Web 2.0” framework for JSF, i.e. it provides a set of JSF components which are AJAX-enabled. It was a bit of a struggle to get working with Tomcat 6.0, but I got there in the end!

Anyway, I’ve been using it for a couple of days now and I really like it. The AJAX is handled completely transparently to you – you just design your JSF application as you would do normally, and IceFaces will handle the AJAX. As an example, it’s really this simple to add an AJAX based table to your JSF page:

1. Use an IceFaces “dataTable” component
2. Have an IceFaces commandButton call the backing bean to populate the table with data (for example, search results)
3. The data table is updated automatically without needing a page refresh
4. …

    Ok, I admit it, items 4 and 5 are not part of it. But still, I think it’s pretty good going.

    There is a bit of configuration to do before you start, but then that’s the same with pretty much any framework I know!

    What I’m trying to do at the moment is set up a “Loading” message, i.e. when you click on a button which will execute a long operation (for example, doing a text comparison on a lot of database fields) a loading message will be shown. By default no message is shown, and I can’t find a way of automatically displaying one for every call (ala DWR).