Recent Notes

Displaying keyword search results 31 - 40
Created by Fang on January 28, 2012 13:24:09    Last update: January 28, 2012 13:31:22
This is a simple JSP custom tags library with tag body. Just like the JSF counterpart , it splits a string and repeats the body for each word, i.e., with this markup: <%@ taglib uri="http://custom.tag.com/demo" prefix... output: <html> <body> <p>Hello Tigger!</p> <p>H... With Maven, this is the directory structure: ./src ./src/main ./src/main/resources ./s... There are three files to write: pom.xml : <project xmlns="http://maven.apache.org/POM/4.0.0"... src/main/java/tagdemo/IterateTag.java : package tagdemo; import java.io.IOException... src/main/resources/META-INF/demotag.tld : <?xml version="1.0" encoding="UTF-8"?> <!DO... Build with: mvn clean install To use it as a dependency in other Maven projects: <dependency> <groupId>tag-demo</groupId> ...
Created by zhidao on January 23, 2012 14:58:58    Last update: January 23, 2012 14:58:58
This exception occurs when the Java object attribute is of type String, while the database column is of type CHAR(n), and hibernate.hbm2ddl.auto is validate in persistence.xml . There are two solutions: Add columnDefinition to the @Column annotation: @Column(name = “STATE_CODE”, columnDefinition = “c... Remove hibernate.hbm2ddl.auto from persistence.xml .
Created by zhidao on January 22, 2012 21:18:19    Last update: January 22, 2012 21:18:45
Once in a while, people want to set the context root of a web application in web.xml . Let me remind myself and others here: context root is not set in web.xml! . The context root is specified by things outside of the webapp : For web application packaged inside a EAR, context root can be specified in the context-root element of the web module: <application xmlns="http://java.sun.com/xml/ns/j2e... For web application deployed standalone, the configuration is container specific. For the JBoss container, it may be specified in jboss-web.xml : <jboss-web> <context-root>bank</context-roo...
Created by Dr. Xi on January 17, 2012 11:58:16    Last update: January 17, 2012 11:58:16
Steps to configure JavaMail resource for Tomcat 6 & 7: Install JavaMail jar: download the JavaMail API , unzip the archive and copy mail.jar to $CATALINA_HOME/lib . Add JavaMail resource to $CATALINA_BASE/conf/context.xml : <?xml version="1.0"?> <Context> . ... Add resource-ref for the JavaMail resource to your webapp WEB-INF/web.xml : <?xml version="1.0" encoding="UTF-8"?> <web-app... Use the JavaMail resource in your webapp: // import javax.naming.*; // import javax.mail....
Created by nogeek on December 29, 2011 13:31:44    Last update: December 29, 2011 14:29:13
Tomcat allows you to create multiple server instances for the same installation. The installation directory is identified as CATALINA_HOME , the instance directory is identified as CATALINA_BASE . Here are the steps: Create a base directory for the new instance, for example: /home/nogeek/tomcat1 . Create the subdirectories: mkdir -p /home/nogeek/tomcat/{bin,conf,logs,temp,w... Copy web.xml from the installation directory: cp $CATALINA_HOME/conf/web.xml /home/nogeek/tomcat... Copy logging.properties from the installation directory: cp $CATALINA_HOME/conf/logging.properties /home/no... Create server.xml under tomcat1/conf : <?xml version='1.0' encoding='utf-8'?> <Server ... Create script setenv.sh under tomcat1/bin : # Edit this file to set custom options # Tomcat... Copy startup.sh and shutdown.sh from the installation directory. Add the following two lines to the beginning of each: CATALINA_BASE=/home/nogeek/tomcat1 export CATAL... Create a soft link for catalina.sh in tomcat1/bin : $ ln -s ~/apache-tomcat-7.0.22/bin/catalina.sh cat...
Created by Fang on December 06, 2011 19:03:25    Last update: December 07, 2011 08:54:11
Our custom tag, as implemented in the previous note , is broken when a template is used. Create a template file ( home-template.xhtml ): <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Stric... and a test page that uses it ( home.xhtml ): <?xml version="1.0" encoding="UTF-8"?> <ui:comp... Then request the page with URL: http://localhost:8080/facelet-demo/home.jsf?name=Jack . You'll find that our hello tag works inside ui:repeat but fails to get the value defined by ui:param ! What's the problem? Our hello tag implementation evaluated the EL with the wrong EL context! This is the corrected implementation: package com.example; import java.io.IOExcep...
Created by Fang on December 06, 2011 12:36:31    Last update: December 06, 2011 12:37:23
I need Maven to generate web.xml based on the target environment. For example: <context-param> <param-name>javax.faces.P... should be translated to <context-param> <param-name>javax.faces.P... for the dev environment, and to <context-param> <param-name>javax.faces.P... in the prod environment. This is the relevant pom.xml section using resources filter: <build> <resources> <resource> <d... With the webResources filter: <build> <plugins> <plugin> <group...
Created by Fang on December 05, 2011 14:56:47    Last update: December 05, 2011 14:57:09
This works for Tomcat. It may or may not work for other servlet containers. As far as I know it's not in the standards spec. In web.xml: <context-param> <param-name>env</param-name> ... If you start Tomcat without defining env , then #{initParam['env']} is ${env} . If you start Tomcat with -Denv=dev in JAVA_OPTS , then #{initParam['env']} is dev
Created by Fang on December 05, 2011 13:04:11    Last update: December 05, 2011 13:04:11
Facelet requires strict XML syntax, so unmatched tags (start with no end, etc) generate errors. This is a trick to workaround that. The following code generates a row for every three items and for each row assigns a row id: <!-- using ui:repeat --> <ui:repeat var="name" ...
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/Greeter.java ): package com.example; public class Greeter {... Add our custom EL resolver ( src/main/java/com/example/ELResolver.java ): 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......
Previous  1 2 3 4 5 6 7 8 9 10 Next