Matt RaibleMatt Raible is a Web Developer and Java Champion. Connect with him on LinkedIn.

The Angular Mini-Book The Angular Mini-Book is a guide to getting started with Angular. You'll learn how to develop a bare-bones application, test it, and deploy it. Then you'll move on to adding Bootstrap, Angular Material, continuous integration, and authentication.

Spring Boot is a popular framework for building REST APIs. You'll learn how to integrate Angular with Spring Boot and use security best practices like HTTPS and a content security policy.

For book updates, follow @angular_book on Twitter.

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.

[NFJS Denver] David Geary and Advanced JSF

David is going to cover some JSF advanced topics: data table, tiles integration, custom components and validators. I was talking with Rick Hightower last night. He mentioned that he's been doing a fair amount of work with JSF lately and really likes it. He actually said he thinks he can develop a webapp faster with JSF than he can with Struts. He also said that JSF ships with a lot of what you need - and a lot of the JSF books seem to cover how to add new stuff (custom components and validators) you don't need. This is to say that the books tend to cover the features of JSF, rather than how to develop successful projects with JSF. I said I thought it'd be nice if there were some JSF books by folks who'd used it to deliver applications. More of a "here's what you need to know" kindof manual. I think that's what JSF needs.

The <h:dataTable> in JSF is pretty much the same as the <c:forEach> tag in JSTL. An interesting note on the JSF expression language - it starts with a # instead of a $. For example:

<h:dataTable value='#{tableData.names}' var='name'>
...
</h:dataTable>

The major difference between JSF and JSTL's expression language is that JSF EL can access managed beans. The JSP 2.0, JSTL and JSF expert groups are going to work together to try and synch up their expression languages. Personally, I don't see why the JSF folks didn't just use JSTL and simply include managed beans in the lookup logic. Here's a wierd one - if you use any "template text", i.e. in a dataTable - you have to wrap the text with <f:verbatim>text</f:verbatim>. David says this is one of the embarrasing things about JSF. He hopes it'll be fixed in the next version.

The <h:dataTable> looks very similar to the DisplayTag. Sweet - that's one less thing I'll have to worry about when creating a JSF app. I've said it before and I'll say it again - my two favorite tag libraries are the DisplayTag and Struts Menu. As I'm learning new frameworks, one of my major goals is to reproduce the same functionality I enjoy in my Struts+JSP apps. It's been pretty simple so far with Spring and WebWork, since both support JSP. However, it might get a bit tricky with Tapestry and JSF. I'm sure it'll be possible (and hopefully easier) to reproduce this functionality, it's just a big unknown at this time.

"Form" beans in JSF are not like form beans in Struts. It's really just a class that doesn't extend anything and has action handler methods. An interesting point - the actionListener's value (which is really a class.methodName) can be any class in any scope OR it can be a managed bean. How about some code:

public class Form { 
    public void changeLocale(ActionEvent e) { 
        FacesContext context = FacesContext.getCurrentInstance(); 
        Map requestParams = context.getExternalContext(). 
                            getRequestParameterMap(); 
        String locale = (String) requestParams.get("locale"); 
        if ("english".equals(locale)) { 
            context.getViewRoot().setLocale(Locale.UK); 
        } else if ("german".equals(locale)) { 
            context.getViewRoot().setLocale(Locale.GERMANY); 
        } 
    } 
}

The major reason behind the FacesContext is to support Portlets. So rather than using a ServletContext or PortletContext, the FacesContext provides a level of abstraction. The underlying theme of JSF: To be as flexible as possible. This is to say that there are many ways to do things with JSF. I often think it's better to have less choices when learning a technology, but once you're versed in it - choices are great. I guess I just wanna know the best way to do things, not all the options. Actions are for business logic, ActionListeners are for UI logic. ActionListeners are always fired before Actions - in the event that you have an actionListener and an action defined for the same component. Listeners and Actions are really just methods on a class and they can actually both be in the same class. JSF is starting to appeal to me. This session has been one of the fastest so far - there's only 20 minutes left and it feels like it's flown by.

JSF ships with converters for dates and currencies out-of-the-box - cool! Now David is explaining about a custom CreditCard converter. This is what Rick was talking about last night. Why do we need to know this stuff? Would a normal talk on another MVC Framework talk about converters and validation? I bet not. I think it's a good topic - maybe something that other frameworks should cover more visibly. The Converter interface has two methods: Object getAsObject() and String getAsString(). The Validator interface has one method: void validate(FacesContext context, UIComponent c). I just asked David about using Commons Validator instead of JSF's core validator. He said, "Yes, it's possible." Sweet! You can use Commons Validator with Struts, JSF and Spring! Now if we could only get support for it in WebWork and Tapestry - then I'd eliminate my need to learn another validation engine.

Now David is talking about using Tiles with JSF. It looks as simple as using the <tiles:insert> tag to insert dynamic content into an <f:subview>. Any time you insert a tiles component, you need to wrap it in an <f:subview> tag. That was short - we're done talking about Tiles. I had some questions - i.e. can you refer to a definition directly from an action or in the action's navigation definition? Oh well, onto custom components and renderers. Custom components and renderers seems to me to be something that should be left out of these types of presentations. Sure, it's cool they're possible - but who's using them? Have you needed them in a real-world JSF application? I only want to know the things I need to know to develop a real-world JSF webapp. Sorry, I forgot - there aren't any real-world webapps written with JSF. If I'm wrong - send me a link. ;-)

This presentation was good - it inspires me to learn some more about JSF. Maybe there'll be some projects in my next gig that require JSF - that would be wicked cool. After all, the best way to learn this stuff is to get paid to do it. If nothing else, I'll get to learn it later this year when I write AppFuse's web layer in JSF.

Posted in Java at May 22 2004, 04:15:13 PM MDT 2 Comments
Comments:

JSF is definitely growing on me as well. I have been reading through O'Reilly's JavaServer Faces and liking what I see. I have not done any Struts in a while, but hopefully I will be able to do some stuff with JSF and see how it compares.

Posted by dsuspense on May 22, 2004 at 09:20 PM MDT #

Our company has a JSF project somewhere around the 30-40% done level. Should be shipped in 3-4 months. Everything I hear is it's working well.

Posted by gerryg on May 24, 2004 at 11:34 AM MDT #

Post a Comment:
  • HTML Syntax: Allowed