Recent Notes

Displaying keyword search results 1 - 10
Created by zhidao on April 25, 2012 14:56:38    Last update: April 25, 2012 14:56:38
Lacking better alternatives, this is how I render a global validation error: <spring:bind path="changePasswordForm"> <c:if ... <form:errors> without path attribute seems to work too: <form:errors cssClass="ui-error"/>
Created by Fang on March 15, 2012 10:24:35    Last update: March 15, 2012 10:24:35
Suppose that I have an email field annotated with: @NotEmpty(message="Please enter email address") ... Bean validation will trigger two errors when no email address is entered: the email field is empty an empty email field is not a valid email address Displaying both errors to the user with <form:errors> would be redundant and confusing: <%@ taglib uri="http://www.springframework.org/tag... This is how to display the first error only: <spring:bind path="emailAddress"> <c:if test="$...
Created by Dr. Xi on March 14, 2012 14:23:14    Last update: March 14, 2012 14:23:14
If forgotPasswordForm.error is a String and not null, you cannot test the error condition with: <!-- This does not work! --> <c:if test="${forg... You have to use "not empty": <c:if test="${not empty forgotPasswordForm.error}"...
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 freyo on September 07, 2011 16:46:14    Last update: September 07, 2011 19:23:00
The Android unit test framework is based on JUnit 3 , not JUnit 4. Test cases have to extend junit.framework.TestCase or a subclass (such as android.test.InstrumentationTestCase ). Tests are identified by public methods whose name starts with test , not methods annotated with @Test (as in JUnit 4). An Android test suite is packaged as an APK, just like the application being tested. To create a test package, first you need to identify the application package it is testing. Google suggests to put the test package source in a directory named tests/ alongside the src/ directory of the main application. At runtime, Android instrumentation loads both the test package and the application under test into the same process. Therefore, the tests can invoke methods on...
Created by jinx on May 03, 2011 11:43:26    Last update: May 03, 2011 11:43:26
The PHP function strval returns the string value of a variable. It does the same thing as casting a variable to string, or automatic conversion where string is expected. Conversion rules: Type String Value Boolean TRUE '1' Boolean FALSE '' (empty string) integer of float string representing the number Array The string 'Array' Object Result of __toString() if defined, error otherwise Resource 'Resource id #n' , where n is a number assigned to the resource. NULL '' (empty string) Example: <?php set_error_handler(function($errno, $errst... Results: bool(true) --------------------- strval: '1'...
Created by freyo on April 18, 2011 15:08:21    Last update: April 18, 2011 15:12:20
Generate android project $ ~/android-sdk-linux_86/tools/android create proj... Create XML file res/xml/books.xml : <?xml version="1.0"?> <catalog> <book id=... Edit layout ( res/layout/main.xml ): <?xml version="1.0" encoding="utf-8"?> <Lin... Edit code ( src/com/android/xmlres/XMLResource.java ): package com.android.xmlres; import java.io.... Change activity label from app_name to booklist ( AndroidManifest.xml ): <?xml version="1.0" encoding="utf-8"?> <manifes... Add value for string resource ( res/values/string.xml ): <?xml version="1.0" encoding="utf-8"?> <resourc... Deploy and test: ant install
Created by Dr. Xi on March 29, 2011 16:06:57    Last update: April 01, 2011 12:33:52
This utility class retrieves SSL certificates from the server and print them out to the stdout. The output can be saved to a file and imported to a Java keystore. This is useful in your test environment where the SSL certificate is self-signed. import java.io.InputStream; import java.io.Outp... Retrieve and import the a certificate: E:\test>java RetrieveSSLCert 192.168.69.144 8081 >...
Created by Dr. Xi on March 02, 2011 11:39:18    Last update: March 09, 2011 12:19:30
Some peculiarities about Java PrintWriter: PrintWriter never throws any exceptions. From JavaDoc : Methods in this class never throw I/O exceptions, although some of its constructors may. The client may inquire as to whether any errors have occurred by invoking checkError(). When error occurs, you'll never know anything more than that it occured, because checkError returns boolean. When a character is out of the range of the character encoding of the PrintWriter, it prints a question mark (?). But this is not an error. Test code: import java.io.*; public class TestPrintWri... Latin1 test result: java TestPrintWriter iso-8859-1 | od -bc 000000... UTF-8 test result: java TestPrintWriter utf-8 | od -bc 0000000 141... Also, the constructor throws a FileNotFoundException when you try to write to a...
Created by Dr. Xi on February 09, 2009 23:14:15    Last update: February 09, 2009 23:14:15
This example demonstrates the general steps in creating a custom Java class loader. Normally a class loader would consult its parent class loader when asked to load a class. If it's not loaded by the parent class loader, then the class loader would try to load the class on its own. This class loader tries to load the requested class on its own first, and delegates to the parent only when a java.lang.SecurityException is thrown (which happens when it tries to load core Java classes such as java.lang.String ). The classes are loaded from CLASSPATH through the getResourceAsStream call. It's important to note that when a class is loaded with a certain class loader, all classes referenced from that class are also loaded through the...