Recent Notes

Displaying keyword search results 1 - 10
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 December 01, 2011 18:54:54    Last update: December 01, 2011 18:54:54
Use the varStatus attribute with the ui:repeat tag to get the iteration index: <ui:repeat varStatus="status" var="item" value="#{... The varStatus attribute specifies the name of the exported request scoped variable for the status of the iteration.The object is a POJO with the following read-only JavaBeans properties. This scoped variable has nested visibility. begin of type Integer end of type Integer index of type int step of type Integer even of type boolean odd of type boolean first of type boolean last of type boolean
Created by Fang on November 22, 2011 10:40:16    Last update: November 22, 2011 10:40:16
This is an example that uses tag handler, UI component and renderer together to support a custom taglib. The main purpose is to show how these components play together. The tag renders <ui:param name="extra" value="el interpreted"/> ... as <h3>my:foreach</h3> <ul class="css class" extra... These are the files: The tag handler ( src/main/java/com/example/ForeachTagHandler.java ): package com.example; import java.util.Map; ... The UI component ( src/main/java/com/example/UIForeach.java ): package com.example; import java.io.IOExcep... The renderer ( src/main/java/com/example/ForeachRenderer.java ): package com.example; import java.io.IOExcep... Faces config ( src/main/resources/META-INF/faces-config.xml ): <?xml version="1.0" encoding="UTF-8"?> <faces-c... Taglib config ( src/main/resources/META-INF/foreach.taglib.xml ): <?xml version="1.0" encoding="UTF-8"?> <facelet...
Created by Fang on November 08, 2011 20:55:00    Last update: November 21, 2011 18:19:44
In the simple taglib example , I used a tag handler class to implement a taglib. This is an example to implement a taglib with a UI component. The purpose is to use a custom tag to split a string and print each part in a separate paragraph, i.e., print <p>john</p> <p>steve</p> <p>mike</p> with custom tag <my:foreach> : <my:foreach var="who" value="john steve mike"> ... These are the files: pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0"... src/main/java/com/example/UIForeash.java : package com.example; import java.io.IOExcep... src/main/resources/META-INF/faces-config.xml : <?xml version="1.0" encoding="UTF-8"?> <faces-c... src/main/resources/META-INF/foreach.taglib.xml : <?xml version="1.0" encoding="UTF-8"?> <facelet... How to use: Put the JAR file generated by the above project in the WEB-INF/lib folder of the web app. If the web app is a Maven project, just add the taglib project as a dependency:...
Created by magnum on September 11, 2011 19:46:09    Last update: September 11, 2011 19:46:09
A pair of C functions convert between an Internet address and a string (ASCII): #include <arpa/inet.h> /* * Returns a poin... However , these functions do not support IPv6. The new pair is: #include <arpa/inet.h> /* Convert a Internet ad... Examples: #include <sys/socket.h> #include <netinet/in.h>...
Created by Dr. Xi on July 11, 2011 12:04:52    Last update: July 11, 2011 12:04:52
From the Java Language Specification : Because some type information is erased during compilation, not all types are available at run time. Types that are completely available at run time are known as reifiable types . A type is reifiable if and only if one of the following holds: It refers to a non-generic type declaration. It is a parameterized type in which all type arguments are unbounded wildcards. It is a raw type. It is a primitive type. It is an array type whose component type is reifiable. For example: int is a reifiable type (primitive type) List is a reifiable type (raw type) List<?> is a reifiable type (parameterized type with unbound wildcards) List<String> is not a reifiable type (generic type) Class<?> is...
Created by alfa on July 01, 2011 13:16:12    Last update: July 01, 2011 13:16:12
This is a simple doclet that prints all public methods and their parameter names and types. Code import com.sun.javadoc.*; public class List... Compile javac -cp $JAVA_HOME/lib/tools.jar:. ListMethodsDo... Use javadoc -doclet ListMethodsDoclet -sourcepath /pat...
Created by alfa on May 27, 2011 11:19:29    Last update: May 31, 2011 07:56:26
This is a utility to convert a string value to one of the primitive type values. It is useful in Java reflection code where the value comes in as a string (e.g., from XML parsing), and the type of the value cannot be decided until runtime. import java.util.*; import java.lang.reflect.*;... Note: This method can be extended to convert string to more complex types by writing a converter for the destination type. For example, to convert string to date: public class DateConverter { public static ... Usage: Date d = (Date) ConvertUtil.convert("10/12/2010", ...
Created by alfa on May 26, 2011 14:23:33    Last update: May 26, 2011 14:25:42
For Java arrays, the class name is [ followed by an encoded name of the element class. The number of [ characters represents the number of dimensions of the array. The class name encoding is following: Element Type Encoding boolean Z byte B char C class or interface L classname; double D float F int I long J short S Example: public class ClassNameEncoding { public sta...
Created by alfa on May 24, 2011 16:08:34    Last update: May 24, 2011 16:09:02
There are two ways to get the Class object for primitive types: Type name followed by .class : Class intClass = int.class TYPE field for the corresponding wrapper class: Class doubleClass = Double.TYPE; Class.forName() does not work for primitive types. But it works for primitive arrays: Class c1 = int[].class; Class c2 = Class.forNam...
Previous  1 2 3 Next