By Max Katz | Article Rating: |
|
May 28, 2010 05:39 PM EDT | Reads: |
782 |

Many rich components (from rich: tag library) provide client-side JavaScript API. Being client-side means it’s happening only in the browser. We would have to click submit or fire an Ajax request to submit the changes. How do you find what JavaScript functions are available on a particularity component? The place to find this information is in the User Guide.
Let’s take a rich:listShuttle as an example. Here is a link to the component in User Guide. If you look at the very top, you will see five links. Click on Reference Data. You will now see JavaScript API table. This is the place where all JavaScript functions are listed. For any other component, you would do the same.
To use these functions, we first need to use a built-in #{rich:component(‘id’)} function in RichFaces. This will give us a reference to the available API for a particular component. We then just append the function name, so it looks like this: #{rich:component(‘id’)}.functionName();
Here is rich:listShuttle component:
Source:
<rich:listShuttle var="air" id="airlines"
sourceValue="#{airBean.airlines}"
targetValue="#{airBean.target}"
converter="airlineConverter"
sourceListWidth="220"
targetListWidth="220">
<f:facet name="sourceCaption">Major U.S based airlines</f:facet>
<f:facet name="targetCaption">My favorite airlines</f:facet>
<h:column>
<f:facet name="header">Name</f:facet>
#{air.name}
</h:column>
<h:column>
<f:facet name="header">Logo</f:facet>
<h:graphicImage value="#{air.logoImage}" width="39" height="32" />
</h:column>
</rich:listShuttle>
Looking at the available API, let’s say we would like to place four buttons under the component that would perform the same actions you can do with Copy All, Copy, Remove and Remove All. Adding the following:
<input type="button" value="Copy All"
onclick="#{rich:component('airlines')}.copyAll();" />
<input type="button" value="Copy"
onclick="#{rich:component('airlines')}.copy();" />
<input type="button" value="Remove"
onclick="#{rich:component('airlines')}.remove();" />
<input type="button" value="Remove All"
onclick="#{rich:component('airlines')}.removeAll();" />
We are using a standard HTML button as they are all client-side functions. We then use #{rich:component(‘id’)} built-in function and reference the appropriate JavaScript API.
Firing an Ajax request is done the same way even if you didn’t have the four buttons. We can place a button and click it once we are done with editing. This is similar to filling out a form and clicking submit. If we want an Ajax request to be fired every time we change either the list or the order, we can use a4j:support tag to accomplish that.
<rich:listShuttle var="air" id="airlines"
sourceValue="#{airBean.airlines}"
targetValue="#{airBean.target}"
converter="airlineConverter"
sourceListWidth="220"
targetListWidth="220">
<f:facet name="sourceCaption">Major U.S based airlines</f:facet>
<f:facet name="targetCaption">My favorite airlines</f:facet>
<h:column>
<f:facet name="header">Name</f:facet>
#{air.name}
</h:column>
<h:column>
<f:facet name="header">Logo</f:facet>
<h:graphicImage value="#{air.logoImage}" width="39" height="32" />
</h:column>
<a4j:support event="onlistchanged" reRender="out"/>
<a4j:support event="onorderchanged" reRender="out"/>
</rich:listShuttle>
<input type="button" value="Copy All"
onclick="#{rich:component('airlines')}.copyAll();" />
<input type="button" value="Copy"
onclick="#{rich:component('airlines')}.copy();" />
<input type="button" value="Remove"
onclick="#{rich:component('airlines')}.remove();" />
<input type="button" value="Remove All"
onclick="#{rich:component('airlines')}.removeAll();" />
<rich:dataList id="out" columns="3"
value="#{airBean.target}" var="air">
#{air.name}
</rich:dataList>
We added two a4j:suppor tags with appropriate events and rich:dataList to display the result.
Read the original blog entry...
Published May 28, 2010 Reads 782
Copyright © 2010 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By Max Katz
Max Katz is a Senior Systems Engineer at Exadel. He has been helping customers jump-start their RIA development as well as providing mentoring, consulting, and training. Max is a recognized subject matter expert in the JSF developer community. He has provided JSF/RichFaces training for the past four years, presented at many conferences, and written several published articles on JSF-related topics. Max also leads Exadel's RIA strategy and writes about RIA technologies in his blog, http://mkblog.exadel.com. He is an author of "Practical RichFaces" book (Apress). Max holds a BS in computer science from the University of California, Davis.
- An Exclusive Interview with Oracle, Cloud Expo 2010 Diamond Sponsor
- The Next Chapter in the Virtualization Story Begins
- Unveiling the java.lang.Out OfMemoryError
- Is MySQL Doomed to Extinction?
- Gosling Out of Oracle
- Gosling Hints He Left Oracle over Money
- 101 on jQuery Selector Performance
- Leveraging Public Clouds to SaaS-Enable Enterprise Applications
- Bravo, Google!
- It's the Java vs. C++ Shootout Revisited!
- Today iPad is the Only Whore in Town
- Larry Says What Everyone Thinks About Sun
- An Exclusive Interview with Oracle, Cloud Expo 2010 Diamond Sponsor
- The Next Chapter in the Virtualization Story Begins
- Unveiling the java.lang.Out OfMemoryError
- HTML5 Web Sockets: A Quantum Leap in Scalability for the Web
- Cloud Computing Bootcamp Returns to Cloud Expo in New York April 20, 2010
- Is MySQL Doomed to Extinction?
- Gosling Out of Oracle
- Gosling Hints He Left Oracle over Money
- 101 on jQuery Selector Performance
- Leveraging Public Clouds to SaaS-Enable Enterprise Applications
- Bravo, Google!
- Novell Owns Unix
- A Cup of AJAX? Nay, Just Regular Java Please
- Java Developer's Journal Exclusive: 2006 "JDJ Editors' Choice" Awards
- The i-Technology Right Stuff
- JavaServer Faces (JSF) vs Struts
- Rich Internet Applications with Adobe Flex 2 and Java
- Java vs C++ "Shootout" Revisited
- Bean-Managed Persistence Using a Proxy List
- Reporting Made Easy with JasperReports and Hibernate
- Creating a Pet Store Application with JavaServer Faces, Spring, and Hibernate
- What's New in Eclipse?
- Why Do 'Cool Kids' Choose Ruby or PHP to Build Websites Instead of Java?
- i-Technology Predictions for 2007: Where's It All Headed?
- ');
for(i = 0; i < google_ads.length; ++i)
{
document.write('
- ');
document.write('' + google_ads[i].line1 + '
'); document.write('' + google_ads[i].visible_url + '
'); document.write(google_ads[i].line2 + ' ' + google_ads[i].line3); document.write(' ');
}
document.write('