Displaying keyword search results 1 - 10
Created by Fang on March 06, 2012 12:24:53 Last update: March 06, 2012 12:24:53
Validation groups can be used to control which rules validation rules to run. A validation group can be identified by any Java interface (not class!). Multiple validation groups may be specified when validating. In this example, I added a validation group named MyValidationGroup ( src/main/java/com/example/MyValidationGroup.java in Maven project):
package com.example; public interface MyVal...and added a @Size rule for a person's name, because my database can only store up to 15 characters for a person's name:
package com.example; import javax.validatio...Now validate Person with a JUnit test ( src/test/java/com/example/TestPersonWithGroup.java in Maven project):
package com.example; import java.util.Set; ...Test with " mvn clean test ". The rules where groups is not specified, which belong to the javax.validation.groups.Default group, are not executed with these tests.
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 installTo use it as a dependency in other Maven projects:
<dependency> <groupId>tag-demo</groupId> ...
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 Dr. Xi on November 11, 2011 10:05:22 Last update: November 11, 2011 10:12:01
This is an HTML image tag filter using Java regex. It takes a string, finds the img tags, replaces the src attribute with one provided by the filter, then adds a class name to the class attribute.
import java.util.regex.*; import java.io.*; ...Test file:
<div id="HTML snippet"> <img src="img/big/txt-m...
Created by freyo on May 13, 2011 15:45:29 Last update: September 20, 2011 08:08:12
This is an Android app that dumps any binarized xml file as plain text - to the sdcard on the device or emulator. build.xml :
<?xml version="1.0" encoding="UTF-8"?> <project...AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?> <man...res/layout/main.xml
<?xml version="1.0" encoding="utf-8"?> <Lin...res/values/strings.xml :
<?xml version="1.0" encoding="utf-8"?> <res...src/com/android/xmltool/DumpXml.java
package com.android.xmltool; import java.ut...Screenshot Pre-built APK can be downloaded from: http://code.google.com/p/android-binxml-dump/
Created by freyo on April 12, 2011 15:13:32 Last update: May 03, 2011 15:20:55
Create new project
$ tools/android create project \ > --package co...Edit res/values/string.xml , add strings for the main screen.
<?xml version="1.0" encoding="utf-8"?> <resourc...Add widgets to main layout ( res/layout/main.xml ).
<?xml version="1.0" encoding="utf-8"?> <LinearL...Edit src/com/android/apkinfo/GetAPKPermissions.java and change contents to:
package com.android.apkinfo; import android...Install the debug package to the emulator:
ant installThe screen should look like: Add display permissions activity. Start by creating a new layout res/layout/display_permissions.xml :
<?xml version="1.0" encoding="utf-8"?> <LinearL...Add the strings used by the new Activity ( res/values/strings.xml ):
<?xml version="1.0" encoding="utf-8"?> <resourc...Add the Display Permissions Activity ( src/com/android/apkinfo/DisplayPermissions.java ):
package com.android.apkinfo; import android...Change src/com/android/apkinfo/GetAPKPermissions.java to invoke the Display Permissions Activity:
package com.android.apkinfo; import android...Declare Display Permissions Activity in AndroidManifest.xml :
<?xml version="1.0" encoding="utf-8"?> <manifes......
Created by Dr. Xi on January 14, 2010 00:28:27 Last update: March 30, 2011 15:37:44
A task that a Java developer does so frequently is to find out where a certain class can be found - to resolve compilation errors, classpath issues, or version conflicts of the same class introduced by multiple class loaders. A long while back I wrote a simple Perl script to perform the task. Later I was informed that there are Swing based Jar Browser and Jars Browser . Then, there are a couple of shell one-liners:
# one liner 1 find -name "*.jar" -print0 | xarg...But all of them share the same problem: if a class is in a jar nested in another jar, it cannot be found. Such is the case for a class inside a jar under the WEB-INF/lib directory of a...
Created by Dr. Xi on October 16, 2008 20:45:40 Last update: March 28, 2011 20:23:22
Java's built-in classes are way too complex/flexible for a simple protocol like HTTP. This is a wrapper to simplify HTTP GET and POST.
import java.io.*; import java.net.*; imp...A simple test:
import java.io.*; import java.util.*; ...
Created by voodoo on July 11, 2009 15:14:55 Last update: July 29, 2010 22:45:48
cURL is a command line tool for transferring files with URL syntax. The main purpose and use for cURL is to automate unattended file transfers or sequences of operations. It's really easy to see HTTP headers with curl:
C:\>curl --head http://www.google.com HTTP/1.0 ...or, headers and page together (dump headers to stdout):
$ curl --dump-header - http://www.google.com HTTP/...Download openssl from openssl.org:
C:\>curl --help Usage: curl [options...] <url> ...