Matt RaibleMatt Raible is a Java Champion and Developer Advocate at Okta. developer.okta.com

The JHipster Mini-Book The JHipster Mini-Book is a guide to getting started with hip technologies today: Angular, Bootstrap, and Spring Boot. All of these frameworks are wrapped up in an easy-to-use project called JHipster.

This book shows you how to build an app with JHipster, and guides you through the plethora of tools, techniques and options you can use. Furthermore, it explains the UI and API building blocks so you understand the underpinnings of your great application.

For book updates, follow @jhipster-book on Twitter.

10+ YEARS


Over 10 years ago, I wrote my first blog post. Since then, I've authored books, had kids, traveled the world, found Trish and blogged about it all.

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. =P~

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 in Java at Aug 06 2004, 10:35:05 AM MDT 4 Comments
Comments:

!>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? :-) Well, SUN uses a listener too. look in core.tld ;-) and with your message-thing, i guess a later version of Spec will solve this...!?! btw. i hadn't played too much with this issue. and libs, well ORO is needed in MyFaces-RegExp-Validator, which uses commons-validator, which uses ORO :-) diggester for config-impl, which uses commons-collection. btw. some other extra-validators are using commons-validator but if you all extra-components, you will need more of the commons: beanutils,el and fileupload. (see example-app) myfaces.jar includes myfaces-components (it is an extra (custom-components <x:ANY_COMPONENT/>) for developers that want use SUN, or else) myfaces-jsf-api is not included in myfaces.jar, because it is *only* the api. if you are writing an JSF-App in your classpath you will have only this API-Jar. Regards, Matthias

Posted by Matthias Weßendorf on August 06, 2004 at 12:55 PM MDT #

I was suspicious of the title of this blog entry "The Joy of developing with JSF". I've not used it but I'm still scared of it. A company that cannot get JSPs right cannot get JSF right either in my opinion :)

Posted by larry on August 08, 2004 at 01:07 PM MDT #

I of course mean that Sun can't get it right.

Posted by larry on August 08, 2004 at 01:08 PM MDT #

BTW, why isn't "div" a choice instead of "table"

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 09:52 AM MDT #

Post a Comment:
Comments are closed for this entry.