Notes by Fang

Displaying notes 41 - 50
Created by Fang on February 28, 2012 11:36:22    Last update: February 28, 2012 11:36:22
To set a CSS property: $('div.left').css('position', 'absolute'); To clear the property: $('div.left').css('position', '');
Created by Fang on February 27, 2012 13:23:14    Last update: February 27, 2012 13:23:14
For Jackson 1.7 and above: // import org.codehaus.jackson.map.ObjectMapper; ... For Jackson 1.6 and below: // import org.codehaus.jackson.map.ObjectMapper; ...
Created by Fang on February 27, 2012 12:19:19    Last update: February 27, 2012 12:19:19
Mapping Java objects to Jackson JSON is pretty simple. But if you name a JSON field wrong, you'll get the "Unrecognized field ... (Class ...), not marked as ignorable" error. The rule for mapping a Java bean attribute name to a JSON field name is: lower all leading capital letters until the first lower case letter . For example, this Java class: package com.example; public class Person { ... maps to this JSON string: { "firstName": "Jane", "lastName": "... Test code: package com.example; import java.net.URL; ...
Created by Fang on February 21, 2012 20:54:23    Last update: February 21, 2012 20:57:57
Tomcat gzip compression filter can be turned on with " compression=on " in server.xml : <Connector port="8080" protocol="HTTP/1.1" ... The default compressed MIME types are: text/html,text/xml,text/plain . It would be nice to add other types: <Connector port="8080" protocol="HTT...
Created by Fang on February 21, 2012 20:33:58    Last update: February 21, 2012 20:33:58
You can customize Tomcat error page with error code: <error-page> <error-code>404</error-code> ... or Java exception type: <error-page> <exception-type>java.lang.Throwab... Either error-code or exception-type is required, but not both. There's no way to aggregate error codes, such as: <!-- This does not work! --> <error-page> ... Customizing error pages is about the only way to suppress the default stack trace in Tomcat in case of an unhandled exception.
Created by Fang on February 17, 2012 14:35:25    Last update: February 17, 2012 14:36:25
Javadoc for javax.validation.Validation gives three ways to bootstrap JSR303 validation: Build default validator factory: ValidatorFactory factory = Validation.buildDefault... The logic for buildDefaultValidatorFactory is: if XML configuration ( META-INF/validation.xml ) defines a provider, use it. if XML configuration does not exist or does not define a provider, use the first provider returned by ValidationProviderResolver . Use custom ValidationProviderResolver : Configuration<?> configuration = Validation ... Ask for a specific provider by class: EXAMPLEConfiguration configuration = Validation ...
Created by Fang on February 16, 2012 12:27:55    Last update: February 16, 2012 12:34:58
Here are some ways to run a main method using Maven: Use the exec plugin: mvn exec:java -Dexec.mainClass="com.example.App" or, with arguments: mvn exec:java -Dexec.mainClass="com.example.App" -... Attach it to a build phase with the build element: <build> <plugins> <plugin> ... If you want to run main from Maven, it's probably just some test code. You are better off just to write a test case, or call the main method from a test class: package com.example; import junit.framework...
Created by Fang on February 15, 2012 21:26:46    Last update: February 15, 2012 21:26:46
Add configuration variables for the surefire plugin to use system properties in Maven test: <build> <plugins> <plugin> <group...
Created by Fang on February 15, 2012 21:11:02    Last update: February 15, 2012 21:11:02
Error: java.lang.NoClassDefFoundError: org/slf4j/helpers/... Cause: had slf4j-nop as dependency, but did not have slf4j-api. Solution: add dependency for slf4j-api. <dependency> <groupId>org.slf4j</groupId> ...
Created by Fang on February 15, 2012 21:03:57    Last update: February 15, 2012 21:03:57
Error: java.lang.NoClassDefFoundError: org/slf4j/impl/Sta... Soluton: add Maven dependency for one of slf4j-nop , slf4j-simple , slf4j-log4j12 , slf4j-jdk14 . For example: <dependency> <groupId>org.slf4j</groupId> ... or <dependency> <groupId>org.slf4j</groupId> ...
Previous  1 2 3 4 5 6 7 8 9 10 Next