Tag-Archive: jsf

JSF: Multiple ‚javax.faces.ViewState‘ hidden fields

If you happen to have more than one h:form in your JavaServer Faces page, JSF will generate a hidden input field with javax.faces.ViewState as its name and id for each form. This breaks XHTML compatability because you have more than one element with the same id which isn’t allowed. I recently came across this myself and had some trouble finding a solution on Google. The problem results from an error in the JSF specification itself and thus cannot be solved easily but both major implementations have builtin workarounds:

For MyFaces, you can specify a context parameter in your web.xml called org.apache.myfaces.RENDER_VIEWSTATE_ID and set it to false. It will prevent MyFaces from rendering duplicate ids. For more information please refer to the MyFaces Bugtracking system (MYFACES-1700).

If you use the reference implementation (currently Mojarra), the name of the context parameter for the web.xml is com.sun.faces.enableViewStateIdRendering and you must also set it to false to prevent the RI from generating duplicate ids. For more information, please refer to the JSF-RI FAQ or the bugtracking system (issue 443).

Developing lightweight Java web applications – Part 5: Templating with Facelets

Update 2012-05-28: I have deleted the project over at Google Code since I never finished it and it is outdated by now. Please refer to other, more state-of-the-art tutorials regarding building web applications with Java. In addition, comments are also closed on these posts.

Turning the app into a webapp

After creating a small persistence layer for our JPokerStats application, it is now time to finally create a web application out of our sources. If you already have the source files from the previous parts, you may have noticed the src/main/webapp directory that was created by the Maven archetype plugin. Let’s start here.

Getting the sources

As always, you can either go the project website or checkout the associated tag from the source control system:

svn checkout http://jpokerstats.googlecode.com/svn/tags/tutorial_part_05

Integrating Faces and Facelets

A web.xml is already present, and for a JSF application we will need to declare the JSF servlet here. We will also add some additional configuration options for debugging purposes and will map all requests to the /faces/ context to the servlet. This results in the following basic web.xml:

Weiterlesen…

Developing lightweight Java web applications – Part 4: Testing the persistence using Spring

Update 2012-05-28: I have deleted the project over at Google Code since I never finished it and it is outdated by now. Please refer to other, more state-of-the-art tutorials regarding building web applications with Java. In addition, comments are also closed on these posts.

Now that all persistence classes are ready, we are going to see if they work the way we want. As we are going to use Spring in the web application, we can also use it for the tests as well, because the Spring IoC container is suitable for standalone applications and provides easy to configure testing facilities.

(Some people have asked me to use the more… function in these articles, so I will try that here.)

Getting the sources

As always, you can either go the project website or checkout the associated tag from the source control system:

svn checkout http://jpokerstats.googlecode.com/svn/tags/tutorial_part_04

Changes that became necessary

While writing this part of the tutorial, I had to change some of the classes to work the way I wanted. The most important change is switching the temporal type startTime and endTime in the Game class from TemporalType.TIME to TemporalType.TIMESTAMP. The reason behind this is the fact, that times saved to the database and loaded again are no longer equal (in terms of equals()) to the times before the save. The times contained are identical, but something else isn’t, so I had to switch as timestamps compare correctly.

As I am also learning while writing this, it may happen from time to time that I need to revise the code from a previous part of the tutorial. I will inform you of these changes as I do now.

Configuring Spring

We need a configuration file to configure Spring persistence, so we’ll create one for testing purposes. Don’t be discouraged by all the declarations in there, I’m going to explain them later on.

Weiterlesen…

Developing lightweight Java web applications – Part 3: Persistence

Update 2012-05-28: I have deleted the project over at Google Code since I never finished it and it is outdated by now. Please refer to other, more state-of-the-art tutorials regarding building web applications with Java. In addition, comments are also closed on these posts.

In the last part of the tutorial, we spent some time with the basic setup of the project and wrote our first classes that we’re going to use as JPA entities. You might recall the simple entity/relationship diagram from the last part that showed how these classes, that JPA will map to database tables for us, are related to each other. Let’s recap:

  • A game can have many results
  • A result belongs to exactly one game and to exactly one player
  • A player can have many results

Weiterlesen…

Developing lightweight Java web applications – Part 2: Getting started

Update 2012-05-28: I have deleted the project over at Google Code since I never finished it and it is outdated by now. Please refer to other, more state-of-the-art tutorials regarding building web applications with Java. In addition, comments are also closed on these posts.

Welcome to part two of my tutorial for developing lightweight Java web applications! I meanwhile created an online code repository for the source files yo that you may refer to them more easily. You can either visit the project site or you can checkout the source files representing this part of the tutorial by using Subversion and calling the following command:

I have always been the hands-on guy, and I’ve always disliked documentations and tutorials that explain aspect of something without a surrounding context So in this tutorial, I’m going to explain the aspects of lightweight Java web applications by using a complete example application that actually does something.

Weiterlesen…