Monday, July 02, 2007

VWP (Woodstock) JSF MessageGroup Tip

It is funny how often we as programmers do things that later cause us extra work.

How many of you while developing a JSF Page use a MessageGroup to display debugging information? I bet your intent was to delete, or not to display (visibility/render) it later...

Here is a tip that will make your life easier....

1. In your web.xml file add an environment entry called displayMessageGroups like below.


2. We will use this to inject a resource into our Application Bean to set it for the whole project.

3. Open the Application Bean (usually ApplicationBean1) and add the following:
@Resource(name = "displayMessageGroups")
private boolean displayMessageGroups;

public boolean isDisplayMessageGroups() {
return displayMessageGroups;
}
This will allow us to change the value from true/false by simply changing the web.xml file if we need to turn on the messages for debugging.

NOTE: I am using auto-boxing on the Boolean --> boolean conversions.

4. Now bind the component by using the properties for the MessageGroup components in your project.

NOTE: You will want to bind the render property and not the visible property. We do not want to add additional downloaded components to the page if we are not planning on using them. This is good style.





This will save you a lot of time later and make debugging easier if you need it.

Popular Posts