Configuring Ajax functionality in Woodstock

Untitled Document

This document shows how to use Woodstock textField's embedded autocomplete functionality. Attached is the complete NB 6.0 project configured for Tomcat that presents sample code.

Download complete source code of sample project - NOTE: JAR files have been removed from the zipped project - so add your own libraries as specified below:

Set up your environment

Setting up your environment is very important step. Woodstock uses jsf-extensions for its JSF-bound Ajax functionality, and jsf-extentions will not function properly if not setup. Thankfully, this is pretty easy to do.

General requirements for any Woodstock Ajax enabled component:

- make sure to include all required for Woodstock libraries. Attached project requires the following libraries added:

   commons-beanutils.jar
   commons-collections.jar
   commons-digester.jar
   commons-fileupload-1.0.jar
   commons-logging.jar
   dataprovider.jar
   jhall.jar
   jsf-extensions-common-0.1.jar
   jsf-extensions-dynamic-faces-0.1.jar
   json-2.jar
   webui-jsf-suntheme.jar
   webui-jsf.jar

 

- add ThemeServlet to the web.xml file ( see attached)

 
 <servlet>
 <servlet-name>ThemeServlet</servlet-name>
 <servlet-class>com.sun.webui.theme.ThemeServlet</servlet-class>
 <load-on-startup>2</load-on-startup>
 </servlet>
 
<servlet-mapping>
   <servlet-name>ThemeServlet</servlet-name>
   <url-pattern>/theme/\*</url-pattern>
   </servlet-mapping>

- add PARTIAL lifecycle parameter to FacesServlet (!!!)

 <servlet>
 <servlet-name>FacesServlet</servlet-name>
 <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
 <init-param>
 <param-name>javax.faces.LIFECYCLE_ID</param-name>
 <param-value>com.sun.faces.lifecycle.PARTIAL</param-value>
 </init-param>
 <load-on-startup>1</load-on-startup>
 </servlet>
 

 

 

Specific for autoComplete functionality:

- add Bean definition to faces-config.xml

 <managed-bean>
 <description>The backing bean for the field autoComplete example</description>
 <managed-bean-name>AutoCompleteBean</managed-bean-name>
 <managed-bean-class>autocomplete.AutoCompleteBean</managed-bean-class>
 <managed-bean-scope>session</managed-bean-scope>
 </managed-bean>

 

Create JSP page

See attached for the example. Important to note::

1. The head tag should contain flag to enable loading of jsf-extentions:

<webuijsf:head title="Field Component Tests"  debug="true" webuiAll="true" webuiJsfx="true"> 
  

2. the textField tag should contain autoComplete and autoCompleteExpression as specified in TLD documentation:

 <webuijsf:textField
   autoComplete="true"
   autoCompleteExpression = "#{AutoCompleteBean.getOptions}"
     text="#{AutoCompleteBean.text}"
 id = "tf" toolTip="tooltip" 
 columns="30" 
 required   = "true"
 label = ""
 />

 

Create back-end implementation

See src/autocomplete java file for example. AutoCompleteBean implements com.sun.webui.jsf.model.AutoComplete interface which defines the signature of the method to provide options:

 public Option[] getOptions(String filter);

 

Run the page

For the test application attached, point your browser to http://localhost:PORTNUMBER/autocomplete_jsf/faces/welcomeJSF.jsp and start typing in the textfield.

 

Please check or report any issues at https://woodstock.dev.java.net/servlets/ProjectIssues

Comments:

Thanks a lot, I've been struggling to include Woodstock into my current projects. I don't want to install it as a Netbeans component - I have no use for its visual web editor. I'm gonna try this ASAP, I can report any issues later.

Thanks again.

Posted by guest on April 02, 2008 at 07:28 AM MDT #

I downloaded your code and executed it on GlassFish, very cool.

Looks like the dependency on JSF extensions doesn't make this functionality very "Visual Web" friendly. Are there any plans to integrate this functionality into NetBeans Visual Web?

Posted by David R. Heffelfinger on April 15, 2008 at 11:35 AM MDT #

Never mind, I just realized that jsf-extensions gets added as a dependency automatically for Visual Web JSF projects.

Posted by David R. Heffelfinger on April 15, 2008 at 12:56 PM MDT #

por favor ayuda para colocarle un color de fondo a un textfield no he podido hacerlo
ayuda porfavor

Posted by Jaider Rdoriguez on April 19, 2008 at 09:29 AM MDT #

my test

Posted by guest on May 02, 2008 at 02:53 AM MDT #

Hello,

Thanks for this example, I used a database instead of the properties file, and I want to reflect the LABEL selected to the textField but the VALUE to a staticText component.

For filling the Option component , I did the following:

options[counter++] = new Option(c3.getCustomerId(),c3.getName());

Does somebody know what can I do?

Grettings!

Posted by NetBeaner on June 11, 2008 at 05:15 AM MDT #

Thanks a lot man!! I couldn't get async functionality to work until I bumped into this blog.

Posted by guest on August 20, 2008 at 06:47 AM MDT #

fdfg

Posted by guest on August 25, 2008 at 10:36 PM MDT #

I'm using this example in a test project and it works fine, the only issue I found is that the popup list overlaps the texfield and I didn't find the solution. Can you tell me what do this?

Posted by Victor Sosa on September 05, 2008 at 07:51 AM MDT #

Doesnt work for me, I get an exception:
java.lang.IllegalStateException: Class returned from AsyncResponse.getPartialTraversalViewRoot must be a UIComponent
at com.sun.faces.extensions.avatar.lifecycle.PartialTraversalLifecycle.render(PartialTraversalLifecycle.java:132)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:266)

Posted by Cesar on October 15, 2008 at 04:27 AM MDT #

To solve the overlaying thing set the z-order in the style to 1

Posted by Paul Clevett on December 14, 2008 at 11:21 PM MST #

Excelent job!

Posted by esmata on January 21, 2011 at 01:40 AM MST #

Post a Comment:
  • HTML Syntax: NOT allowed
About

Dmitry Kushner

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today