Custom Servlets and PrimeFaces Ajax Requests

UI Components for JSF
Post Reply
erickmartinez
Posts: 3
Joined: 10 Jun 2011, 07:14

10 Jun 2011, 07:40

I am having some problems trying to implement PrimeFaces autocomplete in a facelet template client located at /WEB-INF/ directory.

It seems PrimeFaces is returning the real path to the facelet client in order to send autocomplete ajax requests.

1. I created a Servlet to map urlPatterns to a facelets located at /WEB-INF/view/
using

Code: Select all

request.getRequestDispatcher("/WEB-INF/view"+userPath+".faces")
       .forward(request, response);
In order to have the Faces Servlet render my facelet template client
at /WEB-INF/view/faceletClient.xhtml

2. In the facelet client I have a autocomplete element initialized as follows:

Code: Select all

<p:autoComplete id="countryCode" value="#{CountryBean.text}" completeMethod="#{CountryBean.complete}"  maxResults="100"/>
3. Defined the complete method in the CountryBean as follows:

Code: Select all

public List<String> complete(String query) {
   List<String> results = new ArrayList<String>();
   List<Country> queryResults = countryFacade.findByName(query);
   for (int i = 0; i < queryResults.size(); i++) {
      results.add(queryResults.get(i).getCountry());
   }
   return results;
}
4.Deploy and run the application at

http://localhost.8080/myapp/admin/faceletClient

5. I looked at the source code where the autocomplete widget is declared and realized it is using /WEB-INF/view/faceletClient.faces as the request url.

Obviously this url is unaccessible to ajax requests and autocomplete will never populate.

On the contrary, if the faceletClient.xhtml is located in the webroot, url is well formed and the requests are done correctly.

Is there any way I can get this url to point to the url pattern that is recognized by the servlet?
Should I completely abandon the Idea of using Servlets as controllers for my application?

I am using PrimeFaces v2.2.1, Mojarra JSF implementation

In addition to PrimeFaces I am using only smoothness.jar and mysql/j connector libraries

Application server is glassfish 3.1, I am using servlet 3.0

Any advice is appreciated!

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 48 guests