Archive for February, 2006

Creating AJAX and Rich Internet Components with JSF - Part 2

Written by coregps on Sunday, February 26th, 2006 in Java, AJAX.

If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!

Creating AJAX and Rich Internet Components with JSF - Part 2 ? In our previous article - ‘Rich Internet Components with JavaServer Faces’ (JDJ, Vol. 10, issue 11) - we discussed how JavaServer Faces can fulfill new presentation requirements without sacrificing application developer productivity building Rich Internet Applications (RIA). We discussed how JSF component writers can utilize technologies, such as AJAX and Mozilla XUL, to provide application developers with rich, interactive, and reusable components.

Creating AJAX and Rich Internet Components with JSF - Part 1

Written by coregps on Sunday, February 26th, 2006 in Java, AJAX.

Creating AJAX and Rich Internet Components with JSF - Part 1 ? JavaServer Faces (JSF) standardizes the server-side component model for Web application development but doesn’t standardize the presentation layer at the browser. In a series of articles we are going to look at how JSF can fulfill new presentation requirements without sacrificing application developer productivity building Rich Internet Applications (RIA). AJAX has gained momentum primarily due to the XMLHttpRequest browser object, which supports asynchronous communication with any business services used by the Web application. Popular sites such as Google Mail and Google Suggest use AJAX to deliver RIA.

AJAX based Google Page Creator

Written by coregps on Sunday, February 26th, 2006 in AJAX, Web Design.

Google has launched a new exciting AJAX based product - Google Page Creator. It is a free tool that lets us create web pages online through browser and publish them to web space hosted on Google servers with one click. We can create more pages and change the look and the layout of them. When these pages are ready, we can publish them. These pages can be visited at http://yourgmailusername.googlepages.com. In addition, Google provides up to 100MB of space for web pages and uploaded files.
To use Google Page Creator, you must have a Gmail account. Visit http://pages.google.com for more information.

Master index of the NetBeans tutorials

Written by coregps on Friday, February 24th, 2006 in Java.

Sang Shin maintains a master index of NetBeans tutorials and articles which can be visited at http://www.javapassion.com/netbeans/masterindex.html. Thanks a lot for his excellent work!

Close an IE window without prompt

Written by coregps on Friday, February 3rd, 2006 in Web Design.

Usually, we need to close an IE window without prompt, the code below can achieve this.



<html>
<head>
<script type=”text/javascript”>
function closeWindow() {
  this.focus();
  self.opener = this;
  self.close();
}
</script>
</head>


<input type=”button” onclick=”closeWindow()” value=”close” />


</html>

Gathering form data for AJAX posting

Written by coregps on Thursday, February 2nd, 2006 in AJAX.

When migrating an existing application to AJAX-based technologies, we need to make some change the exising code. For example, to submit a form, the code maybe changed to:

function add2Cart(frmObj) {
    var url = “shopping.jsp”;
    var data = “productid=” + frmObj.productid.value + “&amount=” + frmObj.amount.value + “&price=” + frmObj.price.value;
    xmlhttp.onreadystatechange = handler;
    xmlhttp.open(”POST”, url, true);
    xmlhttp.setRequestHeader(”Content-Type”, “application/x-www-form-urlencoded; charset=UTF-8″);
    xmlhttp.send(data);
}

function handler() {
      if (xmlhttp.readyState == 4) {
         if ( xmlhttp.status == 200) {
            alert(”success”);
         } else {
            alert(’failed”);
         }
      }
}

However, it is horrible to change the code like above. The following javascript function can be used to gether form data.

function getFormValues(obj) {
    var queryStr = “”;
    for (i = 0; i < obj.childNodes.length; i++) {
        if (obj.childNodes[i].tagName == “input”) {
            if (obj.childNodes[i].type == “text” || obj.childNodes[i].type == “hidden”) {
               queryStr += obj.childNodes[i].name + “=” + obj.childNodes[i].value + “&”;
            }
            if (obj.childNodes[i].type == “checkbox”) {
               if (obj.childNodes[i].checked) {
                  queryStr += obj.childNodes[i].name + “=” + obj.childNodes [i].value + “&”;
               } else {
                  queryStr += obj.childNodes[i].name + “=&”;
               }
            }
            if (obj.childNodes[i].type == “radio”) {
               if (obj.childNodes[i].checked) {
                  queryStr += obj.childNodes[i].name + “=” + obj.childNodes[i].value + “&”;
               }
            }
        } 
        if (obj.childNodes[i].tagName == “select”) {
            var sel = obj.childNodes[i];
            queryStr += sel.name + “=” + sel.options[sel.selectedIndex ].value + “&”;
        }
    }
    queryStr = queryStr.substr(0, (queryStr.length - 1));
    return queryStr;
}

Now, we can chanage the code something like this:

function add2Cart(frmObj) {
    var url = “shopping.jsp”;
    var data = getFormValues(frmObj);
    xmlhttp.onreadystatechange = handler;
    xmlhttp.open(”POST”, url, true);
    xmlhttp.setRequestHeader(”Content-Type”, “application/x-www-form-urlencoded; charset=UTF-8″);
    xmlhttp.send(data);
}

And then invoke the submit function:

<form>
  ….
  <input type=”button” value=”buy” onclick=”add2Cart(this.parentNode)” />
</form>



Site Navigation