Recent Notes
Displaying keyword search results 1 - 10
Created by Fang on March 30, 2012 10:07:25
Last update: March 08, 2013 13:41:57
After a user resets a password, I want to force the user to change the password before she gets access to secured content. This is usually done with a servlet filter. But with Spring MVC, you can also use a HandlerInterceptor . According to Spring JavaDoc: HandlerInterceptor is basically similar to a Servlet 2.3 Filter, but in contrast to the latter it just allows custom pre-processing with the option of prohibiting the execution of the handler itself, and custom post-processing. Filters are more powerful, for example they allow for exchanging the request and response objects that are handed down the chain. Note that a filter gets configured in web.xml, a HandlerInterceptor in the application context. As a basic guideline, fine-grained handler-related preprocessing tasks are candidates...
Created by Dr. Xi on October 08, 2012 11:56:29
Last update: October 08, 2012 11:56:29
This example gets the annotation attributes of of a web service client generated by JAX-WS RI.
The generated web service client looks like this:
import javax.xml.ws.Service;
import javax.xml.w...
This is how to get the attributes for annotation @WebServiceClient :
WebServiceClient wsc = MyTestWebService.class.getA...
Note that even though name , targetNamespace and wsdlLocation are attributes, you get them using a method call.
Also, annotations are available at runtime only when they have RetentionPolicy.RUNTIME .
Created by Fang on July 25, 2012 12:59:47
Last update: July 25, 2012 12:59:47
Example code:
import javax.xml.ws.BindingProvider;
import jav...
Wierdly, even though the response context ( ctx ) itself is a Map, you cannot iterate through the keys. This:
for (String key: ctx.keySet()) {
logger.inf...
fails:
WARN : InternalError - Handler execution resulted ...
Created by zhidao on January 25, 2012 19:27:53
Last update: January 25, 2012 19:28:47
The spring MVC annotation-driven declaration:
<?xml version="1.0" encoding="UTF-8"?> <beans x... does the following magic : Among others, registers: RequestMappingHandlerMapping RequestMappingHandlerAdapter ExceptionHandlerExceptionResolver in support of processing requests with annotated controller methods using annotations such as @RequestMapping , @ExceptionHandler , etc. Enables Spring 3 style type conversion through a ConversionService instance in addition to the JavaBeans PropertyEditors used for Data Binding. Enables support for formatting Number fields using the @NumberFormat annotation through the ConversionService . Enables support for formatting Date, Calendar, Long, and Joda Time fields using the @DateTimeFormat annotation, if Joda Time 1.3 or higher is present on the classpath. Enables support for validating @Controller inputs with @Valid , if a JSR-303 Provider is present on the classpath. Enables HttpMessageConverter support for @RequestBody method parameters and...
Created by zhidao on January 25, 2012 16:07:29
Last update: January 25, 2012 16:07:29
A JSON response is auto-magically returned when you add the @ResponseBody annotation to the return value of a @RequestMapping annotated method:
import org.springframework.stereotype.Controller;
...
For magic to happen, you must:
Add annotation-driven to the org.springframework.web.servlet.DispatcherServlet config xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans x...
Put Jackson jar files on CLASSPATH (i.e., under WEB-INF/lib ), which includes jackson-core-asl-1.6.4.jar and jackson-mapper-asl-1.6.4.jar .
Created by Fang on January 16, 2012 19:32:20
Last update: January 16, 2012 19:32:54
You can submit a form via Ajax by the jQuery Form Plugin . There are two main methods:
ajaxForm : prepares a form for Ajax submit.
Example:
$('#myFormId').ajaxForm({
target: ...
When the form is submitted, it is sent via Ajax.
ajaxSubmit : submit a form via Ajax.
Example:
$('#myForm2').submit(function() {
// i...
jQuery Form Plugin is not in the core jQuery API, so you have to include an additional JS file:
<head>
<script type="text/javascript" ...
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 10, 2011 13:19:13
Last update: December 01, 2011 19:10:43
You can add custom implicit variables to JSF pages by using a custom EL resolver, in two simple steps: Write an ELResolver class to resolve the variable Add the ELResolver to faces-config.xml Starting from the Maven Hello World example: Add faces API and EL dependencies to pom.xml :
<dependencies> <dependency> <groupId>o... Add a simple greeter class ( src/main/java/com/example/Greeter.java ): package com.example; public class Greeter {... Add our custom EL resolver ( src/main/java/com/example/ELResolver.java ): package com.example; import java.util.Itera... Add the custom EL resolver to src/main/resources/META-INF/faces-config.xml <?xml version="1.0" encoding="UTF-8"?> <faces-c... Build JAR with mvn package Drop the JAR into WEB-INF/lib of a webapp and test the new EL with: <h:outputText value="#{Greeter.sayHi('Mike')}"/> Fixed: the setValue method used to throw an exception, which is wrong. @Override public void setValue(ELContext ctx, O......
Created by James on November 27, 2011 12:43:24
Last update: November 27, 2011 12:59:01
An easy to digest stylesheet example for XSLT for Atom. Simply list entry titles and summary:
<?xml version="1.0" encoding="utf-8"?>
<xsl:sty...
To show the first 3 items in atom feed:
<?xml version="1.0" encoding="utf-8"?>
<xsl:sty...
Created by James on November 23, 2011 13:57:51
Last update: November 23, 2011 13:57:51
An easy to digest stylesheet example for XSLT for RSS. Simply list item titles descriptions:
<?xml version="1.0" encoding="utf-8"?>
<xsl:sty...
URL for Google news feed: http://news.google.com/news?ned=us&topic=h&output=rss