Notes by Fang
Displaying keyword search results 1 - 10
Created by Fang on January 14, 2013 14:00:36
Last update: January 14, 2013 14:00:36
Cause: Hibernate reverse engineering generated a column mapping like this:
@Version
@Column(name="VERSION", nullable=false...
Fix: change the mapping to:
@Column(name="VERSION", length=20)
public Strin...
Created by Fang on May 03, 2012 15:07:17
Last update: May 03, 2012 15:07:52
Scaling an image with default Java API loses quality (horribly!):
public static BufferedImage resizeImage(Buffer...
The imgscalr library does the job beautifully. And its' very easy to do:
// import org.imgscalr.Scalr;
public static...
To import the library in Maven:
<dependency>
<groupId>org.imgscalr</groupId>
...
Created by Fang on March 30, 2012 15:04:04
Last update: March 30, 2012 15:04:04
Spring MVC 3.1 can send either JSON or HTML response on the same URL, depending on the type of response requested. With this mechanism, a page can be sent when directly requested from a link, but a JSON response can be sent in response to an AJAX request. This is the controller code:
package com.example; import java.util.Map; ... In the above example, JSON response will be sent when the HTTP request contains header "Accept: application/json". HTML response will be sent then the header is "Accept: */*", or "Accept: text/html", or anything else. You can add a limitation that the HTML response does not produce "application/json". But then the question is which response will be sent when the HTTP header is "Accept: */*"? Both methods will...
Created by Fang on March 30, 2012 10:23:21
Last update: March 30, 2012 10:23:21
These bean types are essential for the Spring MVC framework. I copied them here from the Spring Documentation for quick reference. Bean type Explanation HandlerMapping Maps incoming requests to handlers and a list of pre- and post-processors (handler interceptors) based on some criteria the details of which vary by HandlerMapping implementation. The most popular implementation supports annotated controllers but other implementations exists as well. HandlerAdapter Helps the DispatcherServlet to invoke a handler mapped to a request regardless of the handler is actually invoked. For example, invoking an annotated controller requires resolving various annotations. Thus the main purpose of a HandlerAdapter is to shield the DispatcherServlet from such details. HandlerExceptionResolver Maps exceptions to views also allowing for more complex exception handling code. ViewResolver Resolves logical String-based...
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 10, 2012 16:17:13
Last update: February 10, 2012 16:17:13
The annotation @org.hibernate.annotations.Type overrides the default hibernate mapping type used for a column. This can usually be omitted since Hibernate normaly infers the correct type to use.
But @Type is required in ambiguous scenarios such as a java.util.Date attribute, which can map to SQL DATE , TIME or TIMESTAMP . You use the @Type("timestamp") annotation to tell Hibernate that a timestamp converter should be used, which identifies an instance of org.hibernate.type.TimestampType .
@Type can also be used to identify custom type converters, which can be defined with @TypeDef at the class level:
@TypeDefs(
{
@TypeDef(
na...
or with an xml file:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mappi...
Created by Fang on January 31, 2012 16:27:39
Last update: January 31, 2012 16:27:39
Because Maven dependencies are transitive, the same artifact may be brought in with different version numbers by multiple other dependencies. For example, the current project may depend on artifact A, which in turn depends on artifact C version 1. It may also have immediate dependency on artifact B, which in turn depends on artifact C version 2. Maven resolves these version conflicts in the following ways: Dependency Mediation : If a specific version is not declared in your project POM, Maven resolves the version number by nearest definition , which means it will use the closest dependency in the tree of dependencies for the current project. When dependency depth is the same, it will pick the one that appeared in the POM first. Dependency Management...
Created by Fang on January 16, 2012 19:50:00
Last update: January 16, 2012 19:50:00
jQuery validation plugin hooks into the form submission cycle, so in order to submit a form via Ajax you have to use the submitHandler option of the validate method:
$('#myform').validate({
submitHandler: func...
Or, with jQuery Form Plugin:
$('#myform').validate({
submitHandler: func...
Created by Fang on January 16, 2012 19:32:20
Last update: January 16, 2012 19:32:54
You can submit a form via Ajax by the jQuery Form Plugin . There are two main methods:
ajaxForm : prepares a form for Ajax submit.
Example:
$('#myFormId').ajaxForm({
target: ...
When the form is submitted, it is sent via Ajax.
ajaxSubmit : submit a form via Ajax.
Example:
$('#myForm2').submit(function() {
// i...
jQuery Form Plugin is not in the core jQuery API, so you have to include an additional JS file:
<head>
<script type="text/javascript" ...
Created by Fang on January 16, 2012 15:34:15
Last update: January 16, 2012 15:34:15
Use the .serialize() method to encode the form data for Ajax call:
$.ajax({
url: 'formHandler',
data: $(t...