Recent Posts

RSS Feeds

StockTracker sample JSF/Spring/Hibernate application posted

About a year ago I did a talk at the DJUG and I had a simple app that I developed for that talk. Well I got busy and never posted it. So I spend the last few days sprucing it up to use the lastest versions of stuff and finaly getting it out the door. I still did not get the templating converted to tiles but it should be straightforward and a great learnign exercise for anyone interested in making that conversion. I'd be happy to post any patches that somone sends to me :-)

I will be doing a public JSF/MyFaces class at the end of the month in San Jose for anyone intrested.

Here is the list of stuff that is used in this example;

  • hibernate 3.1 (www.hibernate.org - used hibernate 3.1.2)
  • hibernate tools 3.1-beta4
  • hibernate annotations 3.1-beta8
  • MyFaces 1.1.1 (myfaces.apache.org)
  • DBUnit 2.01
  • Commons Lang 2.0
  • Commons DBCP 1.2.1
  • Commons Pool 1.2
  • Spring 2.0-m2
  • JUnit 3.8.1
  • XDoclet 1.2.3 (although should be removed because its only generating a very simple web.xml file)
  • MySQL - 4.x or 5.x (I used 5.0.18)
  • MySQL JDBC 3.1.12 (not sure if this driver requires 5.0 or not not)
  • Tomcat 5.5.15

One interesting thing I ran into is that Tomcat 5.5.15 forces stuff that goes into the session to be serializable (an oversight on my part initially when I wrote the code). A resonable assertion but it apparently was not enforced in 5.0.x or 5.5.9 because I had to make the page objects serializable to get the app to work. I had to look in the localhost.xxxx-xx-xx.log (the xx's are for the date) to find the error that I was getting.

SEVERE: Servlet.service() for servlet jsp threw exception
javax.faces.el.EvaluationException: Cannot get value for expression '#{!menu.userLoggedIn}'
	at org.apache.myfaces.el.ValueBindingImpl.getValue(ValueBindingImpl.java:397)
	at javax.faces.component.UIComponentBase.isRendered(UIComponentBase.java:822)
	at org.apache.myfaces.renderkit.html.HtmlGridRendererBase.renderChildren(HtmlGridRendererBase.java:176)
	at org.apache.myfaces.renderkit.html.HtmlGridRendererBase.encodeEnd(HtmlGridRendererBase.java:85)
	at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:331)
...snip...
Caused by: java.lang.IllegalArgumentException: setAttribute: Non-serializable attribute
	at org.apache.catalina.session.StandardSession.setAttribute(StandardSession.java:1249)
	at org.apache.catalina.session.StandardSessionFacade.setAttribute(StandardSessionFacade.java:129)
	at org.apache.myfaces.context.servlet.SessionMap.setAttribute(SessionMap.java:50)
	at org.apache.myfaces.context.servlet.AbstractAttributeMap.put(AbstractAttributeMap.java:104)
...snip...
Feb 9, 2006 7:39:03 AM org.apache.catalina.core.ApplicationDispatcher invoke
SEVERE: Servlet.service() for servlet jsp threw exception
javax.faces.el.EvaluationException: Cannot get value for expression '#{!menu.userLoggedIn}'
	at org.apache.myfaces.el.ValueBindingImpl.getValue(ValueBindingImpl.java:397)
	at javax.faces.component.UIComponentBase.isRendered(UIComponentBase.java:822)
	at org.apache.myfaces.renderkit.html.HtmlGridRendererBase.renderChildren(HtmlGridRendererBase.java:176)
	at org.apache.myfaces.renderkit.html.HtmlGridRendererBase.encodeEnd(HtmlGridRendererBase.java:85)
	at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:331)
...snip...
Caused by: java.lang.IllegalArgumentException: setAttribute: Non-serializable attribute
	at org.apache.catalina.session.StandardSession.setAttribute(StandardSession.java:1249)
	at org.apache.catalina.session.StandardSessionFacade.setAttribute(StandardSessionFacade.java:129)
	at org.apache.myfaces.context.servlet.SessionMap.setAttribute(SessionMap.java:50)
	at org.apache.myfaces.context.servlet.AbstractAttributeMap.put(AbstractAttributeMap.java:104)
	at org.apache.myfaces.el.VariableResolverImpl$13.put(VariableResolverImpl.java:192)
	at org.apache.myfaces.el.VariableResolverImpl.resolveVariable(VariableResolverImpl.java:328)
...snip...

The other interesting thing that I noticed is how far along the hibernate annotations are, I had no real problems with my little sample app, of course your millage might varry. Next up I'd like to convert the app to use Cayenne and then get it to deploy on Geronimo... Ah if only I could give up sleep :-)

Anyway here is the screen flow captured in a notation that is easy to do with Omni Graffle. And here is the domain model. And finally for you that are sick of docs and just want to look at the code you can download it here. And finally a pointer to the way back preso here. The code for the example is licensed with the ASF 2.0 license so you are fee to do with it what you will as long as you don't sue me...

Have fun, and any feed back would be greatly appreciated.

Permalink     3 Comments

IBM, Laszlo & JSF - Together at last

If you read TSS you probably have already seen this thread. I am really excited about this concept. I had a discussion last year with a person from IBM at Colorado Software Summit about using flash as the front end for JSF. Not sure that our conversation had anything to do with the Faces for Laszlo work but it is great to see it taking shape.

From my limited look at the samples that come with the download (why doesn't it work with Eclipse and the WTP anyway?) I'm not so sure that the model is right but is is a start.

Here is some sample code that creats a laszlo thing

<laszlo:component id="datagridApp" width="480" height="180">
    <laszlo:clientDataBridge name="dataset1" modelName="company"
                             modelIndex="department" />
    <laszlo:eventBridge id="eb1" eventSource="datagrid1.grid1"
                        eventName="onselect" modelName="company"
                        onEvent="selectEmployee(thisObj,thisEvent)" />
    <![CDATA[
        <include href="faces4laszlo/lzx/tutorial/employeeDatagrid.lzx"/>
        <employeeDatagrid id="datagrid1" width="480" height="180" 
                          datapath="dataset1:/department"
                          contentdatapath="employee" canAddDelete="false"/>
    ]]>
</laszlo:component>

The thing I find interesting is that the laszlo stuff is simply referencing the component which is still created via the xml bindings. I think it would be cool to have the whole thing converted over to JSF. In other words instead of rendering the view as HTML render it as Flash via Laszlo. I've not spent enought time to really think this through but I'm sure I could make it work given enough time ;-)

Permalink     1 Comment

JavaOne Talk

Well I had intended to blog this more than a week ago but its that whole day job thing again...

Fellow MyFaces committer Matthias and I have submitted a talk for JavaOne2005 on JSF & MyFaces. Here is the abstract.

JSF is now a well-known and widely accepted standard in the J2EE landscape. If you are still wondering what JSF is and how it can be used to build robust and easy to maintain applications for the web this presentation is for you. JSF is introduced with a discussion of what it is and how it works. You will understand why we have JSF as well as how it works. We also cover the architectural concepts behind how to build good JSF apps that are easy to understand and maintain. Next up we cover the Apache MyFaces implementation of JSF and some of the really cool extras you get from using MyFaces. These extras are fileupload, calendar, scrollable and editable table and custom validators, to name only some. Also there is built in support for Tiles, which allows you to compose web pages niftily. Another big plus is support for Cell Phones through its WML RenderKit. Best practices are discussed from a practical standpoint next. In other words we will answer the question ?what do I do to build a good JSF app??. We will also discuss how to connect your JSF application to back end services through both a POJO (plain old java object) interface using Spring?s IoC (Inversion of Control, AKA Dependency Injection) as well as interfacing with more traditional back end technology such as EJB?s. Finally we will go through an example with lots of code and a demo of some of the cool things you can do with JSF and MyFaces. In this session attendees will discover JSF and how to use it practically to build web applications.

I'm looking forward to presenting this talk with Matthias. It is something like what I gave at ApacheCon but more focused on the extras of MyFaces. Anyway who knows if we will get in, there must be 100's of JSF talk proposals.

Permalink     1 Comment

JSP must go, or tools must get better

OK, perhaps I'm missing something but this is driving me nuts. When I was building the really simple pages of my app (just a few fields and a couple of buttons) I did not mind the JSP way to build my component tree. But now that I've moved on to the big page that has 40 or so fields and several buttons (yes it messy but that is what the customer wanted) I've decided (again) that I don't like JSP's (or rather I don't like that I can't get tool support to help me spell better). Since I can barely spell my own name many of the attributes were misspelled so I had to build, deploy click through several pages then discover that I misspelled another attribute (grr!). Yes I know I should spell better but where is some compiler support. I have become much worse at spelling (esp method names) since I got completion.

So what I'd really like is a JSP editor that understands the EL and will do completion for me. Anyone found such a thing?

I suppose I could be more careful at spelling but its one of those things that I've decided is superfluous with code completion.

Permalink     7 Comments

Canoo Web Test & JSF

Sometime ago I remember a posting about problems in testing JSF apps with Canoo. Well I'm deep in the troughs of a JSF app and I'm doing testing with Canoo and it works like a champ. So not sure if the JavaScript support has improved to the point that it just works now or what but I'm not having any problems. I am using fairly simple things though. I'm about to get into pageable tables from My Faces. I'll post again once I get that running and let you know how it goes.

Some of the docs for Canoo leave a bit to be desired so let me sum up what I've found so far in testing with Canoo

  • The tests are ant build files, simple and obvious once you get it, it took me an hr of looking at the site to figure that out.
  • Modify the log4j.properties file in the lib directory to get rid of the tons of logging messages. This is in the FAQ but I never read FAQ's ;-)
  • Use the entities stuff as suggested in the docs, its good stuff. I'd like to try out ant 1.6's import and see if that works as well.
  • The tests are not as brittle as I thought they would be, pleasant surprise. I just finished with a moderate sized refactoring and updating the tests was straightforward
  • Use Cargo to start/stop the web container, its fantastic.

I'm already behind because of the crash so i should shut up now.

Permalink     2 Comments

ApacheCon JSF/MyFaces Talk posted

I've finished my ApacheCon talk and mailed it off. I also posted it here.

There is not enough about MyFaces in the talk though. I tried to do an intro to JSF and talk about MyFaces all in one talk and I think its too much. All the example code is using MyFaces so I'll get a chance to do some MyFaces but the content of the slides is just not MyFaces enough. I think I might get rid of some of the 'intro' level stuff and add my MyFaces specific stuff. If you have any thoughts on the matter I'm definitely open to feedback. The biggest problem I have/had is that I've got 1 hr to do the talk in and I can't get all of the info in...

Anyway looking forward to your feedback.

Permalink     2 Comments

Colorado Software Summit

Less than two weeks till CSS. I can't wait!

I'll be talking about JSF, an intro talk and an advanced talk

Hope to see you there!

Permalink     No Comments

MyFaces @ ApacheCon!

I'm really excited that I got a spot @ apacheCon this year talking about MyFaces which is well on the way to becoming an apache project in the jakarta incubator.

If you want to come and throw tomatoes at me come see talk #995 'Building WebApps with MyFaces'

Permalink     1 Comment

Form Validation in JSF

I got an email a couple of days ago with someone asking me about how to do form validation in JSF. I figured that might be a common interest so here is the exchange

The way I'd do what you suggest is to code the validation in a method and have that method invoked from the
action that will determine where to go next (like the submit).

// validation method
public boolean validateForm() {
  // validate the form
  // each field in the form typically has a field in this class
  // where something is not valid add a message
  // if everything is valid return true other wise return false
}

public String submit() {
  boolean valid = validateForm();
  String logicalOutcome = null;
  if(valid) {
    logicalOutcome = "next page";
  } else {
    // null will cause it to return to the same page
    // since you added the messages in the validate method
    // they will be available in your ui if you use <h:messages/>
    logicalOutcome = null;
  }
  return logicalOutcome;
}

then in your faces config file (faces-config.xml typically) you'd have something like this

...
  <navigation-rule>
    <from-view-id>/firstPage.jsp</from-view-id>
    <navigation-case>
      <from-outcome>next page</from-outcome>
      <to-view-id>/otherPage.jsp</to-view-id>
    </navigation-case>
  </navigation-rule>
...

if the form is validated the navigation rule would take you to 'otherPage.jsp', if not since the return is null you'd stay on the same page and display error messages

Hope this helps!

Permalink     No Comments

jsf-spring & RC2

I tried to integrate the two but it does not work. I posted about it on my Eclipse blog because I used some of the cool features in Eclipse debugging support to figure out why.

Permalink     No Comments

JSF & Spring

I've been playing around with JSF & Spring for the last day or so and its really cool being able to configure your beans with DI.

I've been using the jsf-spring project stuff. It works well and the bi-directional nature of it is cool (it makes the JSF 'context' part of the Spring context) but a lot of overkill for me since all I really want to do is inject my 'services' into the page beans.

I was experiencing a problem though with the validation of the faces-config.xml that ships with jsf-spring when deploying to JBoss. For some reason the dtd that's in the jsf jar file is not found at runtime by JBoss. Any pointers to why that's not working would be appreciated. I spent quite a bit of time trying to get the Entity Resolver stuff to work but had no success, and besides it should just work right. Ah well please let me know any pointers you might have.

Since I can easily get by with the greatly simplified stuff that ships with Spring now I'm going to convert to that implementation so it should not be a problem but I'd still like to figure out what was going wrong.

Permalink     No Comments

Ed Burns (JSF RI Lead) posts JSF talk

Ed Burns posted his presentation to the Orlando JUG to the JSF RI site recently.

Tons of cool intro info on JSF as well as a quick explination of what the delta is between JSF & Struts.

Permalink     No Comments

JSF Custom Component Article @ java.net

My article about custom JSF components is online @ java.net here.

Please post your comments or send me an email.

Permalink     No Comments

Creator on the Mac

Despite Matt's dislike for the tool, Creator is actualy quite good on the mac. The deploy cycle is a bit slow but that it probably because its deploying to the Sun J2EE Server instead of anything related to Creator. If you want to deploy elsewhere it seems to be manual (i.e. export .war file, then manually deploy the war file). I did not find it to be way to long on my 1.5GHz powerbook (wall time about 5 to 20 seconds to deploy some of the smallish example from the Field Guide depending on what else I was doing).

It is definitely worth the $99.95 price tag for building that simple web app that does not need a middle tier. I think it hits the VB programmer level quite nicely. By the way the book is aimed right at the correct spot for the 'corporate developer'. Instead of droning on about 'architectural best practices' it goes straight to showing the reader how to build an app with Creator. Even JSF is an 'oh by the way' topic. There are about 10 pages dedicated to JSF. So don't buy the book if you are looking to understand JSF, if you want a book to recommend to people asking you how to create simple web apps then this is the title.

I know people are tired of hearing about the 'corperate developer' but I once worked with a guy that was managing tens of millions of dollars per year with Excell. He was the only guy on the planet that understood all the VB macros, perhaps he was shooting for job security but I think he bought an Excell for Dummies book to try to make his job easier and ended up managing a ton of money with his 'simple' app. I think the Creator tool could become a web app building tool that people like this guy could use. Many of the common code blocks that are required are captured as Clips so its as easy as drag and drop and your code is done.

It is important to note that Creator is not aimed at 'Enterprise Developers'. It does not grok J2EE development. So if you want a tool that will help you build your Stateless Session Beans look elsewhere. If you are looking though to have a tool that will allow you build out simple three tier (browser to servlet container to db) apps then I'd recommend taking a look at Creator.

My next bit of experimenting is going to be related to getting the page objects to connect to back end services (i.e. ejb session beans) to see if we can use Creator to build front ends for 'real' apps :-)

Permalink     No Comments

Studio Creator Up and Running...

I've been working hard @ Sys-Con radio so I've not had a chance to build an application yet but its been running since it finished downloading during the key note. People @ the show can get it for 49.95 for a year I guess. I'll have to find out how to do that... Maybe I'll be able to con them into giving me a free copy so I can blog about it :-)

At any rate here is a screen shot of the app running on my mac.

I guess now I can finally finish my presentation for the Denver JUG.

Permalink     No Comments