JSF Ajax component library

February 19th, 2006

One of the biggest complaints I have heard about JSF is how difficult it can be to use Ajax with. Indeed, it can be difficult to do so, and you often must go outside of the JSF way of doing things in order to get an Ajax component to work. There have been several good components that use Ajax (MyFaces has several) and some good Ajax implementations of the normal JSF components (ie, ICEfaces). However, if you plan on doing something other than exactly what the components do, you are out of luck.

With this problem in mind, I created a set of components to allow a little more flexibility. You can attach an Ajax listener to any input component, and listen for any type of event. Then you attach any number of Ajax Response listeners to that Ajax Call component to do the work after the response is returned. For example, let’s say you have a form where the user needs to put in a model number for a particular product, after which a text box will be filled in with the product name. Your code would look like this:

<t:inputText action=“#{productBean.prodcutName}” value=“#{productBean.productId}”>
<u:AjaxCall event=“onchange”>
<u:AjaxResponse status=“success” forId=“productName” forAttribute=“value” value=“$returnValue” />
<u:AjaxResponse status=“failure” function=“onFailed($returnValue);” />
</uAjaxCall>
</t:inputText>
<t:inputText id=“productName” forceId=“true” value=“#{productBean.productName}” />
<f:verbatim>

<script>
function  onFailed(error){
alert(“There has been an error”  + error);
}

</f:verbatim>

This solution seems a little more flexible than some of the other stuff out there (although, if you want an input suggest box, you should use the one from MyFaces) and follows the JSF model. It uses the prototype.js library for the Ajax calls. I will be providing the source and binaries via SourceForge shortly, thanks to my employer (rFocus, inc) allowing me to release the source. Anyone interested in helping further the development or just using it can contact me, or check back here for updates.

Entry Filed under: Frameworks, J2EE

1 Comment Add your own

Leave a Comment

Required

Required, hidden

Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>

Trackback this post  |  Subscribe to the comments via RSS Feed


Calendar

February 2006
M T W T F S S
    Aug »
 12345
6789101112
13141516171819
20212223242526
2728  

Most Recent Posts