Recent Notes

Displaying keyword search results 1 - 7
Created by Dr. Xi on April 19, 2012 10:10:08    Last update: April 19, 2012 10:11:06
The default servlet for Tomcat is declared in $CATALINA_HOME/conf/web.xml : <servlet> <servlet-name>default</servle... Therefore, static content is rendered by the default configuration unless you override it with your own definitions. If you want to allow directory listing, just change the listing parameter to true : <init-param> <param-name>listings</para... Change the welcome-file-list to display a default page in lieu of a directory listing: <welcome-file-list> <welcome-file>home.xhtml</... Welcome pages are defined at the Web application level.
Created by Fang on November 10, 2011 13:19:13    Last update: December 01, 2011 19:10:43
You can add custom implicit variables to JSF pages by using a custom EL resolver, in two simple steps: Write an ELResolver class to resolve the variable Add the ELResolver to faces-config.xml Starting from the Maven Hello World example: Add faces API and EL dependencies to pom.xml : <dependencies> <dependency> <groupId>o... Add a simple greeter class ( src/main/java/com/example/ ): package com.example; public class Greeter {... Add our custom EL resolver ( src/main/java/com/example/ ): package com.example; import java.util.Itera... Add the custom EL resolver to src/main/resources/META-INF/faces-config.xml <?xml version="1.0" encoding="UTF-8"?> <faces-c... Build JAR with mvn package Drop the JAR into WEB-INF/lib of a webapp and test the new EL with: <h:outputText value="#{Greeter.sayHi('Mike')}"/> Fixed: the setValue method used to throw an exception, which is wrong. @Override public void setValue(ELContext ctx, O......
Created by Fang on November 10, 2011 20:33:46    Last update: November 10, 2011 20:33:46
The stack trace is like this: java.lang.IllegalArgumentException: Component prop... You get this error because you are using the class attribute with a JSF UI component, for which the class attribute cannot be altered. Of course you meant CSS class, not Java class! You can use the styleClass attribute instead of the class attribute. The styleClass attribute becomes the class attribute when the component is rendered. If you can add a tag handler to the UI component, you can alias class to styleClass , which will allow you to use the class attribute on the UI component: import javax.faces.view.facelets.*; pub...
Created by Fang on November 03, 2011 19:47:38    Last update: November 08, 2011 20:24:47
This is a step-by-step example to create a really simple facelet taglib (in JSF 2 with Maven). Create a simple Maven project with: mvn archetype:create -DgroupId=com.example -Dartif... Three files are created as a result: pom.xml src/main/java/com/example/ src/test/java/com/example/ This project should be able to build with: mvn package Add facelet API dependencies to pom.xml : <project xmlns=" The compiler plugin section is optional. Remove src/main/java/com/example/ , create a new Java class as the facelet Tag Handler ( ): package com.example; import This tag handler simply prints a "Hello" message. Create facelet tag declaration file src/main/resources/META-INF/hello.taglib.xml : <?xml version="1.0" encoding="UTF-8"?> <facelet... Build the JAR with mvn clean package Optionally, install it to the local repository: mvn install To use the taglib, simply drop the...
Created by Dr. Xi on November 23, 2010 20:20:01    Last update: March 01, 2011 13:38:51
I tried to find a GZIP compression servlet filter to compress a large log file that we send down to the browser. Most of the implementations I found were overly complicated and many buggy. This is a simple implementation that worked for me. The filter: package filter.demo; import*; i... Config web.xml : <filter> <filter-name>gzipFilter</filte... The ugly anonymous inner class could have been avoided if the servlet API did not insist on ServletResponse.getOutputStream returning the bogus ServletOutputStream class (instead of the plain OutputStream ). Additional Note: In an earlier version of this filter, the gzip headers were added in doFilter , like this: // This is NOT good! if (supportsGzip) { ... It turned out that the ServletResponse methods sendError bypasses the gzip...
Created by Dr. Xi on January 08, 2010 03:53:37    Last update: January 08, 2010 03:54:56
This is an Ant custom task to merge Properties files I lifted from , with some minor bug fixes. Example usage: <taskdef name="mergeProperty" classname="ant.task.... Implementation: package ant.task.addon; import
Created by Dr. Xi on October 23, 2008 03:54:04    Last update: October 23, 2008 03:57:44
Add validator plugin in struts-config.xml <struts-config> . . . ... Set validate="true" on action form <struts-config> <!-- ========== Form Bean De... Add validation rules in validation.xml <?xml version='1.0' encoding='windows-1252'?> <... If you override validate , make sure super.validate is called. package com.example; import javax.servlet.h... Read the documentation: