You're viewing all posts tagged with jsf

jstl tags not working in jsf 2

I was migrating a JSF application to JSF 2 and noticed that none of the JSTL tags worked anymore.  And Googling for a reason for that hasn’t been very helpful as 99% of the posts regarding “JSTL and JSF” just say “don’t”. 

The prevailing wisdom used to be that you shouldn’t mix JSTL and JSF, and once upon a time that was very true.  But JSF and JSTL has worked pretty well together since at least 1.2, and while in general you should avoid JSTL when there’s an equivalent purely JSF-based solution, there are times when it just makes more sense to use JSTL.  So I was disappointed at first to see that this didn’t appear to be working anymore.

Well, it turns out, JSF 2’s Facelets specification requires support for JSTL and both major implementations includes the taglib.xml so we’re good.  There’s no reason to rewrite all those .xhtml files just yet.

It turns out the problem was simply that the taglib namespace had changed from

      xmlns:c=”http://java.sun.com/jstl/core”

to

      xmlns:c=”http://java.sun.com/jsp/jstl/core”

I couldn’t find documentation anywhere about that, so here you go, Googlers.  Hopefully I saved a few of you a couple of headscratching minutes.

JSF Action Methods Not Invoking

I decided to upgrade one of the systems I support to JSF 2.  As if that wasn’t a large enough task, I decided while I’m at it, I would switch from MyFaces to Mojarra and dump Tomahawk while I’m at it.

After removing a lot of the Tomahawk components and the ExtensionsFilter servlet filter, I started to notice that many of my forms did not work anymore.  Clicking on the commandButtons or commandLinks within those forms would simply refresh the page but would not invoke the associated action.  Unfortunately for me, I had made a few dozen other changes besides removing Tomahawk, so the relationship between the two wasn’t that obvious at the time.

I had several forms that were declared like this:

<h:form enctype="multipart/form-data" id="sidebarForm">
...
</h:form>

There was no error message: upon submitting the form from a commandLink or commandButton, the page simply refreshed.  The request never invoked the action methods.  

The fix turned out to be rather simple.  Removing enctype=”multipart/form-data” fixed the problem.

Why was that there to begin with?  Well, because I used to use the Tomahawk inputFileUpload component to allow my clients to upload files.  The Tomahawk ExtensionsFilter allowed JSF to handle multipart form submissions before.

So this might not be likely to happen to anyone else, but if you ever decide to dump Tomahawk like I did, and suddenly notice your forms aren’t working, this might be why.