Recent Notes

Displaying keyword search results 1 - 8
Created by Fang on April 16, 2012 12:58:35    Last update: April 16, 2012 12:58:35
To implement a JSP custom tag with dynamic attributes (for example, to pass-thru arbitrary attributes not handled by the JSP tag): Set the dynamic-attributes element to true in the TLD: <tag> <name>mark</name> <tag-class>c... The tag handler must implement javax.servlet.jsp.tagext.DynamicAttributes : package com.example.jsp; import java.io.*; ...
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 21, 2011 13:49:11    Last update: November 21, 2011 13:49:11
In the test for the simple taglib example , I used a literal string for the name attribute: <my:hello name="Jack"/> What happens if the name attribute contains EL expresson? For example: <my:hello name="#{param['name']}"/> If EL works, the tag should take the value of the " name " request parameter and print it out. But the tag as implemented in the simple taglib example prints the literal string: Hello #{param['name']}! I am FaceletTag. In order to make a tag to recognize EL, we have to use TagAttribute.getValue(FaceletContext ctx) instead of TagAttribute.getValue() . The latter returns the literal value of the attribute. The HelloTagHandler should be changed to: package com.example; import java.io.IOExcep... Rebuild the taglib and test with a URL like this: http://localhost:8080/facelet-test/?name=Jack The tag will print:...
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 Dr. Xi on February 01, 2011 14:38:55    Last update: February 01, 2011 14:40:59
Create the stuff you want to manufacture with the factory: package tc.demo; public class Junk { ... Create the factory: package tc.demo; import java.util.Enumerati... Tell Tomcat to use your factory. Create file context.xml and put it under the directory META-INF of your web application: <Context> <Resource name="/find/junk/here" ... Note that beside name , type and factory , you can put any arbitrary attribute in the Resource element. Access the thing with JNDI: <%@page language="java" import="javax.naming.*,tc.... The server side log looked like this: INFO: jndiName: here INFO: name: scope, value: ... Also note that, in contrast to Tomcat documentation , resource-ref is not needed in web.xml .
Created by James on June 30, 2010 20:14:28    Last update: July 03, 2010 18:41:12
The HTML page <!DOCTYPE html> <html> <head> <title>jQu... Client Side Code // called before upload submit function sta... Server Side Code Using Apache Commons FileUpload as example. Upload code (responds to fileUpload.do ): final HttpSession session = httpServletRequest... Progress code (responds to uploadProgress.do ): HttpSession session = httpServletRequest.getSe...
Created by Fang on April 01, 2010 22:24:58    Last update: April 02, 2010 02:49:38
In this note I'll show you how to create and package a JSP custom tag. The purpose of this tag is to display a random splash image for a home page, among a set of images. We should be able to add or delete candidate splash images from the WAR archive without the need to change the JSP. This is the intended use of the tag: <%@ taglib uri="http://custom.tag.com/demo" prefix... In the above example you provide a set of images named splash*.png (e.g., splash1.png, spalsh2.png, ...), and the tag will pick a random one to display when the JSP is rendered. Let's get started. I'll use Maven for this purpose. Create the standard Maven directory structure ./pom.xml ./src ./src/main ./src/main/jav... pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0"... SplashTag.java package tagdemo; import java.util.ArrayList......
Created by Dr. Xi on January 08, 2010 03:53:37    Last update: January 08, 2010 03:54:56
This is an Ant custom task to merge Properties files I lifted from http://marc.info/?l=ant-user&m=106442688632164&w=2 , with some minor bug fixes. Example usage: <taskdef name="mergeProperty" classname="ant.task.... Implementation: package ant.task.addon; import java.io.Buff...