Recent Notes

Displaying keyword search results 1 - 10
Created by Dr. Xi on March 21, 2013 20:29:14    Last update: March 22, 2013 08:58:08
Spring-WS documentation says you can use a Jaxb object as parameter or return type, provided that it is annotated with javax.xml.bind.annotation.XmlRootElement , or is an instance of javax.xml.bind.JAXBElement . But that's a lot easier said than done! For example, if sayHelloResponse is defined as: <xs:element name="sayHelloResponse" type="tns:sayH... then the JAXB generated class is not annotated with XmlRootElement , therefore, unusable for Spring-WS. You have to define the type as: <xs:element name="sayHelloResponse"> <xs:compl... in order to generate a type annotated with XmlRootElement . But that is not always possible. Alternatively, you can use the Maven plugin maven-jaxb2-plugin with the jaxb2-basics-annotate plugin (yes, plugin inside plugin) to inject the XmlRootElement annotation into the generated JAXB class. This is the pom: <project xmlns="http://maven.apache.org/POM/4.0.0"... and the binding file: <?xml version="1.0" encoding="UTF-8" standalone="y......
Created by James on February 02, 2012 16:09:05    Last update: February 02, 2012 16:09:17
flowplayer is another way to embed Flash in a web page. The code looks like this: <object width="6400" height="380" data="swf/flowpl... You need to download two swf files: http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf http://releases.flowplayer.org/swf/flowplayer.controls-3.2.0.swf
Created by Fang on December 06, 2011 19:03:25    Last update: December 07, 2011 08:54:11
Our custom tag, as implemented in the previous note , is broken when a template is used. Create a template file ( home-template.xhtml ): <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Stric... and a test page that uses it ( home.xhtml ): <?xml version="1.0" encoding="UTF-8"?> <ui:comp... Then request the page with URL: http://localhost:8080/facelet-demo/home.jsf?name=Jack . You'll find that our hello tag works inside ui:repeat but fails to get the value defined by ui:param ! What's the problem? Our hello tag implementation evaluated the EL with the wrong EL context! This is the corrected implementation: package com.example; import java.io.IOExcep...
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 Fang on November 10, 2011 09:26:12    Last update: November 10, 2011 09:26:12
Syntax highlighted XML schema for JSF 2.0 Application Configuration Resource File ( faces-config.xml ). Almost 3000 lines! <?xml version="1.0" encoding="UTF-8"?> <xsd:sch...
Created by Fang on November 02, 2011 16:40:10    Last update: November 02, 2011 16:40:10
Facelet taglib schema from JavaServer Faces Spec 2.0: <xsd:schema targetNamespace="http://java.sun.com/x...
Created by Dr. Xi on July 11, 2011 12:24:10    Last update: July 11, 2011 12:25:44
This code snippet import java.util.*; public class UncheckedCast ... fails with a compilation error and a warning: $ javac -Xlint:unchecked UncheckedCast.java Unc... Because List<String> is not a reifiable type, the Java Runtime does not have enough information to verify the type or do the type casting. This is fixed by changing List<String> to List<?> (or to the raw type List ): public static void main(String[] args) { Ob...
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 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