Recent Notes
Displaying keyword search results 51 - 60
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 09, 2011 11:50:28
Last update: December 09, 2011 11:51:34
Values of Maven properties are accessed with the construct ${...} . Properties come from 5 different sources:
From the environment, for example: ${env.PATH} , ${env.JAVA_HOME} .
From the POM, in the form of ${project.x} . For example: ${project.version} , ${project.groupId} .
From settings.xml , in the form of ${settings.x} . For example: ${settings.offline} , ${settings.interactiveMode} .
From Java system properties, for example: ${java.home} .
Defined within the properties element in the POM. For example ( gae.version ):
<properties>
<gae.version>1.4.2</gae.ve...
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 19:52:15
Last update: December 06, 2011 19:52:15
Resource files under the src/main/resources directory are copied verbatim to the target/classes directory during build. But resources can be filtered by turning on filtering in pom.xml :
<build> <resources> <resource> ... When filtering is turned on, constructs like ${...} are replaced with actual values if they are defined. For example, create a file test.properties : project.stage=${project.stage} The build command " mvn package " simply copies test.properties to target/classes/ . But if you build with: mvn -Dproject.stage=dev package the contents of target/classes/test.properties becomes: project.stage=dev Sometimes you want different resource definitions for different environments, e.g., dev vs. prod. You can achieve that by defining profiles in pom.xml : <profiles> <profile> <id>dev</id> ... In the above, dev is the default profile, prod is defined but not active unless...
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......
Created by Fang on November 28, 2011 21:04:15
Last update: November 28, 2011 21:04:15
Some innocent looking JavaScript may cause a fatal error in a Facelet page. For example:
<script type="text/javascript">
if (items.lengt...
or
<script type="text/javascript">
// jQuery code ...
Because Facelet is strict XML, therefore, < and > must be escaped.
There are several ways to deal with this:
Do not embed JS code directly in the page. Put the code in .js files and include it in the page with the src attribute.
Put JS code in a CDATA section:
<h:outputScript target="head">
<![CDATA...
Use XML entities:
<script type="text/javascript">
// jQuery code ...
Created by James on November 27, 2011 16:02:11
Last update: November 27, 2011 16:02:11
This is an example that uses the XSLTProcessor jQuery plugin for client side XSLT. Unfortunately it didn't work in IE or Chrome. It worked in Firefox but somehow disable-output-escaping="yes" was ignored.
<!DOCTYPE html>
<html xmlns="http://www.w3.org/...