The Joy of developing with JSF
I plan to write up a "My JSF Experience" post later today, but first, I'm forced to rant on the state of JSF implementations. First of all, I must say that JSF isn't so bad. It's cool how you can map buttons to "actions" defined in a navigation entry, as well as to call a method in a managed bean. The problem that I'm experiencing is that the JSF implementations, both from Sun and MyFaces - are errrrr, not so good.
I actually managed to almost finish my simple JSF sample app in one day, but then decided to shoot off some questions to see if I could resolve some remaining issues. Then based on feedback I received, I decided to switch from Sun's RI to MyFaces - not only for the "sortable" grid (I still don't know if it exists), but also Spring supports it w/o using an add-on library.
Ever since I switched, things just haven't gone right. First of all, MyFaces, requires your implement a <listener> in web.xml - who knows why, but you get an error indicating you need it if you don't have it. Standard JSF doesn't require this - why does MyFaces?
OK, I can deal with adding the listener. Everything works as with Sun's RI - and even better since the "layout" attribute of <h:messages> actually works. BTW, why isn't "div" a choice instead of "table" - whoever designed these choices obviously still uses Netscape 4 and table-based layouts. I'm happy now. MyFaces seems to solve the duplicate post issue so if you refresh after adding a record, it just shows a blank form. Cool, I can live with that.
One problem I found, that likely exists in both implementations, is that it's a true pain-in-the-ass to get a declared ResourceBundle in a managed-bean. Here's the method I'm currently using to add a success message:
public void addMessage(String key, String arg) { ApplicationFactory factory = (ApplicationFactory) FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY); String bundleName = factory.getApplication().getMessageBundle(); ResourceBundle messages = ResourceBundle.getBundle(bundleName); MessageFormat form = new MessageFormat(messages.getString(key)); String msg = form.format(new Object[]{arg}); FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, msg, msg)); }
There has to be an easier way! Please tell me there is. I admit that I'm a JSF rookie - having just started using it two days ago, but it seems ridiculous that all the "success message" examples out there don't even consider i18n.
So now I have my success messages working, but I discover that there's no way to escape HTML (using <h:messages>) from my ResourceBundle (to put bold around a part of the message). ALL of the other MVC frameworks I've been dealing with allow this - why doesn't JSF?! Again, I'm hoping someone tells me I'm ignorant and there is a way to do this.
Lastly, I tried to upgrade to the latest MyFaces snapshot from CVS to solve this bug and now I can't even get my fricken app to start up because of this issue.
Are these the hoops that developers have to go through to get started with JSF? Thump, thump, thump. My head is starting to hurt.
Update: I'm an idiot about the "can't get my app to start thing" - I didn't copy all the new myfaces*.jar files into WEB-INF/lib. Heh.
BTW, MyFaces requires a whole slew of JAR files just like Struts. Here's my current inventory:
commons-codec-1.2.jar commons-collections-3.0.jar commons-digester-1.5.jar commons-validator.jar commons-oro.jar commons-logging.jar jstl.jar myfaces.jar myfaces-components.jar myfaces-jsf-api.jar
Posted by Matthias Weßendorf on August 06, 2004 at 06:55 PM MDT #
Posted by larry on August 08, 2004 at 07:07 PM MDT #
Posted by larry on August 08, 2004 at 07:08 PM MDT #
The hand-rolled messages renderer class I mentioned in your other recent JSF comments thread is named "DivMessagesRenderer", and I bet you can guess why. Let me know if you want a rough copy.
Posted by Ray on August 11, 2004 at 03:52 PM MDT #