Recent Notes
Displaying keyword search results 1 - 10
Created by Fang on March 30, 2012 15:04:04
Last update: March 30, 2012 15:04:04
Spring MVC 3.1 can send either JSON or HTML response on the same URL, depending on the type of response requested. With this mechanism, a page can be sent when directly requested from a link, but a JSON response can be sent in response to an AJAX request. This is the controller code:
package com.example; import java.util.Map; ... In the above example, JSON response will be sent when the HTTP request contains header "Accept: application/json". HTML response will be sent then the header is "Accept: */*", or "Accept: text/html", or anything else. You can add a limitation that the HTML response does not produce "application/json". But then the question is which response will be sent when the HTTP header is "Accept: */*"? Both methods will...
Created by magnum on July 26, 2010 15:55:41
Last update: March 28, 2012 15:28:02
Given the URL:
http://www.mydomain.com/myWebApp/theServlet/p1/p2/p3;sid=123?param=abc
This would be the output of the various method calls on HttpServletRequest :
String scheme = request.getScheme(); // ...
Created by Fang on January 16, 2012 19:50:00
Last update: January 16, 2012 19:50:00
jQuery validation plugin hooks into the form submission cycle, so in order to submit a form via Ajax you have to use the submitHandler option of the validate method:
$('#myform').validate({
submitHandler: func...
Or, with jQuery Form Plugin:
$('#myform').validate({
submitHandler: func...
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 January 16, 2012 15:34:15
Last update: January 16, 2012 15:34:15
Use the .serialize() method to encode the form data for Ajax call:
$.ajax({
url: 'formHandler',
data: $(t...
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 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
Created by Fang on November 21, 2011 15:57:49
Last update: November 22, 2011 09:51:26
The improved custom taglib works with existing facelet ui taglibs. For example:
<ui:param name="theName" value="John"/> <my:hel... produces the expected output. However, a problem exists with the ui:repeat tag: <h3>With ui:repeat</h3> <ui:repeat var="theName... When tested with a URL like: http://localhost:8080/facelet-demo/?name=Zack&name... the raw EL prints out the correct names, but my custom tag substitutes empty string for theName2 ! In theory, the response is rendered in the Render Response phase, way after the Apply Request Values phase, actual values should be available to EL. The answer to this anomaly turned out to be very deep ! Yes, right there in the code! I would consider this a bug in facelets implementation, but the JSF spec did not tell what the expected behavior should be. In my custom...
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 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...