Recent Posts

RSS Feeds

Eclipse Live Makes the Eclipse.org site!

The Eclipse news section on the main page has a pointer to the Eclipse Live book @ sourcebeat!

Very Cool!

Permalink     No Comments

Role Based Rendering of UIComponents

This example will show you how to conditionally render a UIComponent based on the users role.

Last week during the JSF Book promo on JavaRanch someone asked about this. I promised to put together a quick demo and here it is...

Stuff about this example...

  • The Page object creates the conditionally rendered component. This was the only way that I could figure out to make it work. If you can think of another please let me know. I spent some time trying to use an expression but there was no way to tell the value I was getting which component was asking if it should render.
  • This simple example uses the Tomcat memory realm instead of a db. For real apps you would want to use a DB realm.
  • The login and login-error pages are really simple.
  • The test for the page uses mock objects of FacesContext and ExternalContext classes. Quick overview here by Vincent Massol. The latest version of the class mocker (instead of just interfaces) is now at 2.1 but the one included with this download is functional.
Hope you enjoy it!

Here is the important code in case you don't want to download the example.

JSP Code

     <h:inputText id="test" binding="#{page.inputField}"/>

The binding attribute binds the actual component to a UIComponent created by the object tied to 'page'. IOW when the view is being rendered it will get the component by calling 'getInputField()' on the page object.

Java Code

  public UIInput getInputField() {
    if (authorized()) {
      inputField.setRendered(true);
    } else {
      inputField.setRendered(false);
    }
    return inputField;
  }
  
  private boolean authorized() {
    boolean authorized = false;
    // if its null try to find it
    if(null == context) {
      context = FacesContext.getCurrentInstance();
    }
    // should never happen...
    if (null != context) {
      // clearly 'foo' is a made up role your check should be
      // more valid
      authorized = context.getExternalContext().isUserInRole("foo");
    }
    return authorized;
  }

Permalink     2 Comments

Arch of JSF Apps Presentation Updated

I finally had time last night to update the Architecture of JSF Applications presentation that I'm doing at the No Fluff Just Stuff Symposiums. You can find the code here.

Enjoy!

Permalink     5 Comments

No longer null, now empty string...

In converting some more of the code from JSF Beta to JSF 1.0 I ran into another gotcha. Previously if I had form fields with nothing in them they would leave the values of the managed beans null. In the 1.0 release they set the values to the empty string (i.e. value.length() == 0). No big deal but my example would not work anymore because it relied on null's.

Permalink     No Comments

Nonobvious Config Error in JSF Beta to 1.0 converstion

I just finished updating all the code for Mastering JavaServer Faces. Apart from the camelCase that I posted about already there were not very many changes to the code.

The custom component chapter though had one gotcha. Since I had a component I had to register that in the faces-config.xml file like this

<component> <component-type>Scroller</component-type> <component-class>calendar.component.UIScroller</component-class> </component> <render-kit> <renderer> <renderer-type>ScrollerRenderer</renderer-type> <renderer-class>calendar.renderer.ScrollerRenderer</renderer-class> </renderer> </render-kit>

I was getting errors like this;

2004-03-05 21:49:21 StandardContext[/chapter_10]Exception sending context initialized event to listener instance of class com.sun.faces.config.ConfigureListener javax.faces.FacesException: java.lang.NullPointerException: Argument Error: One or more parameters are null. at com.sun.faces.config.ConfigureListener.contextInitialized(ConfigureListener.java:310)

I found this thread that discussed some other occurrences of similar errors but I'd already been bitten by the old versions of the jars and fixed that in early chapters. Anyway turns out I'm missing the component-family element from my renderer declaration in the faces-config.xml.

<component> <component-type>Scroller</component-type> <component-class>calendar.component.UIScroller</component-class> </component> <render-kit> <renderer> <component-family<Scroller</component-family> <renderer-type>ScrollerRenderer</renderer-type> <renderer-class>calendar.renderer.ScrollerRenderer</renderer-class> </renderer> </render-kit>

Adding the componet-family did the trick!

Permalink     1 Comment

Cluefulness & Certification

I had a question about SCWCD on the JavaRanch JSF Book Promo about what book to buy for the cert, here is my reply.

What are your thoughts?

I'm not very well versed in the SCWCD exam or the books surrounding it. I tend to shy away from these certifications. I think the biggest part of the tests is being able to perform well in a test taking scenario. The people who pass have proven basic competence (many who have the cert I'm sure are a lot more than competent) and the ability to do well on a test. That does not necessarily mean they are good people to have on my team.

I'm not saying this to discourage you from taking the exam at all or to discount the people who have. I just place a lot of value on the person and their ability to write software. And less on their ability to take a test. So I always make sure to interview people in a way to find out what kind of team member they will be, how are they doing on maintaining a positive learning curve. I rarely even look at the exam cert's someone has or use that as a filtering criteria.

One of the most cluefull guys I know has never graduated college, or received a single cert but he is brilliant, knows 5 or 6 computer languages (Java, Ruby, etc) and can talk about distributed architecture in his sleep.

I know this does not exactly answer your question but the question did not match the title anyway

So what do I recommend? Buy some of the books on cert's, buy the J2EE Patterns book from Alur, Crupi & Malks, read everything you have time for. Then go build something. Open source it or what ever but build something, build a bloger, build a distributed calendar manager, whatever. Make it do as much as you can, use it as a learning exercise and don't worry so much about the feature set just make it have all the features required for you to learn. Then if I interviewed you I'd hire you because you have shown an ability to be self motivated, and that you have the ability to survive a step learning curve. Then if you want to get the cert as gravy go for it, it can't hurt and its nice to have all those acronyms behind your name.

My $0.02 worth.

Permalink     1 Comment

Mastering JSF Finally Finally...

Well I finally finished the JSF book, with the final release of the spec I was concerned that I'd have a lot to change but thankfully the only big thing I had to do was update to camelCase. There were lots of little things but over all not bad and I'm finally finished!

Permalink     No Comments

JSF Ships!

In case you have not heard the JSF 1.0 shipped today!

Permalink     No Comments

Mastering JSF Promo...

The great folks over at JavaRanch are running a promo of the JSF book here. Looking forward to meeting you online in the forums.

Permalink     No Comments

Mastering JavaServer Faces - Finally

I finally submitted the last of the Mastering JSF book today to Wiley! Boy is that a huge relief. I can't wait to see it on the shelves. It has been a long hard road for this book. After the beta version of the spec shipped 2 days before the book was due to be printed... Then a mad scramble to rewrite a lot of the book. Now I can finally get around to updating the JSF presentation. I'll post again when that is done.

Permalink     2 Comments