Commit 3d1af859 authored by Bruce Link's avatar Bruce Link
Browse files

added primefaces autocomplete example

parent e1c307e5
package com.corejsf.autocomplete; package com.corejsf.autocomplete;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.inject.Named; import javax.inject.Named;
import javax.enterprise.context.ApplicationScoped; import javax.enterprise.context.ApplicationScoped;
...@@ -8,36 +10,51 @@ import javax.enterprise.context.ApplicationScoped; ...@@ -8,36 +10,51 @@ import javax.enterprise.context.ApplicationScoped;
@Named @Named
@ApplicationScoped @ApplicationScoped
public class AutoComplete implements Serializable { public class AutoComplete implements Serializable {
String[] locations = {
"Abbotsford", "Agassiz", "Albuquerque", "Aldergrove", "Arvada", "Ashcroft",
"Bahamas", "Baltimore", "Bamfield", "Bayou", "Belgrade", "Bella Coola",
"Boston Bar", "Boulder", "Brighton","Brittany", "Buffalo", "Burnaby",
"Burns Lake",
"Cache Creek", "Campbell Island", "Campbell River", "Chase", "Chemainus",
"Chilliwack", "Clinton", "Colorado Springs", "Comox Valley", "Coquitlem",
"Cortes Island", "Creston",
"D'arcy", "Delta", "Denver", "Dixie", "Douglas Inlet", "Duncan",
"East Sooke", "Esquimalt", "Everett", "Evergreen",
"Fort Collins", "Fort Langley", "Fort Liard", "Fort Nelson", "Fort St. James",
"Fort St. John", "Fort Ware", "Francis Lake",
"Gibsons", "Gilford Island", "Gold River", "Good Hope Lake",
"Haida Gwaii", "Haines", "Hazelton", "Hope", "Hopetown", "Horseshoe Bay",
"Invermere",
"Kamloops", "Keremeos", "Kitamaat Vilage", "Kitimat", "Kitkatla", "Klemtu",
"Kyuquot Sound",
"Ladysmith", "Langley", "Lillooet", "Los Angeles",
"Los Lobos", "Las Vegas", "Loveland", "Lytton",
"Maple Ridge", "Matsqui", "McLeod Lake", "Merritt", "Mill Bay", "Mission",
"Nanaimo", "Nemia Valley", "New Westminster", "North Vancouver",
"Pemberton", "Port Coquitlem", "Port Hardy", "Port Moody", "Port Renfrew",
"Port Simpson", "Prince George", "Prince Rupert", "Princeton",
"Qualicum Beach", "Quesnel",
"Ross River",
"Salmon Arm", "Seattle", "Squamish", "Surrey", "Swindle Island",
"Terrace", "Thompson River", "Tsawwassen",
"Vail", "Valdes Island", "Vancouver", "Vernon", "Victoria",
"Watson Lake", "West Vancouver", "Whistler", "Williams Lake", "Windermere"
};
public String[] getLocations() { public String[] getLocations() {
return new String[] { return locations;
"Abbotsford", "Agassiz", "Albuquerque", "Aldergrove", "Arvada", "Ashcroft", }
"Bahamas", "Baltimore", "Bamfield", "Bayou", "Belgrade", "Bella Coola",
"Boston Bar", "Boulder", "Brighton","Brittany", "Buffalo", "Burnaby", public List<String> complete(String query) {
"Burns Lake", System.out.println("autoComplete.complete(" + query + ")");
"Cache Creek", "Campbell Island", "Campbell River", "Chase", "Chemainus", String lcQuery = query.toLowerCase();
"Chilliwack", "Clinton", "Colorado Springs", "Comox Valley", "Coquitlem", List<String> result = new ArrayList<String>();
"Cortes Island", "Creston", for (String s : locations) {
"D'arcy", "Delta", "Denver", "Dixie", "Douglas Inlet", "Duncan", if (s.toLowerCase().startsWith(lcQuery)) {
"East Sooke", "Esquimalt", "Everett", "Evergreen", result.add(s);
"Fort Collins", "Fort Langley", "Fort Liard", "Fort Nelson", "Fort St. James", }
"Fort St. John", "Fort Ware", "Francis Lake", }
"Gibsons", "Gilford Island", "Gold River", "Good Hope Lake", return result;
"Haida Gwaii", "Haines", "Hazelton", "Hope", "Hopetown", "Horseshoe Bay",
"Invermere",
"Kamloops", "Keremeos", "Kitamaat Vilage", "Kitimat", "Kitkatla", "Klemtu",
"Kyuquot Sound",
"Ladysmith", "Langley", "Lillooet", "Los Angeles",
"Los Lobos", "Las Vegas", "Loveland", "Lytton",
"Maple Ridge", "Matsqui", "McLeod Lake", "Merritt", "Mill Bay", "Mission",
"Nanaimo", "Nemia Valley", "New Westminster", "North Vancouver",
"Pemberton", "Port Coquitlem", "Port Hardy", "Port Moody", "Port Renfrew",
"Port Simpson", "Prince George", "Prince Rupert", "Princeton",
"Qualicum Beach", "Quesnel",
"Ross River",
"Salmon Arm", "Seattle", "Squamish", "Surrey", "Swindle Island",
"Terrace", "Thompson River", "Tsawwassen",
"Vail", "Valdes Island", "Vancouver", "Vernon", "Victoria",
"Watson Lake", "West Vancouver", "Whistler", "Williams Lake", "Windermere"
};
} }
} }
autoCompleteWindowTitle=JSF 2 Ajax autoCompleteWindowTitle=JSF 2 Ajax
locationsPrompt=Locations locationsPrompt=Locations
locationsPrompt2=PrimefacesLocations
loginWindowTitle=JSF 2 Ajax loginWindowTitle=JSF 2 Ajax
loginHeading=Please Log In loginHeading=Please Log In
namePrompt=Name: namePrompt=Name:
......
...@@ -35,4 +35,10 @@ ...@@ -35,4 +35,10 @@
<to-view-id>/autocomplete/index.xhtml</to-view-id> <to-view-id>/autocomplete/index.xhtml</to-view-id>
</navigation-case> </navigation-case>
</navigation-rule> </navigation-rule>
<navigation-rule>
<navigation-case>
<from-outcome>pfautocomplete</from-outcome>
<to-view-id>/autocomplete/indexPrimefaces.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
</faces-config> </faces-config>
\ No newline at end of file
...@@ -3,14 +3,15 @@ ...@@ -3,14 +3,15 @@
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" <html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html" xmlns:h="http://java.sun.com/jsf/html"
xmlns:util="http://java.sun.com/jsf/composite/util"> xmlns:util="http://java.sun.com/jsf/composite/util"
xmlns:p="http://primefaces.org/ui">
<h:head> <h:head>
<title>#{msgs.autoCompleteWindowTitle}</title> <title>#{msgs.autoCompleteWindowTitle}</title>
</h:head> </h:head>
<h:body> <h:body>
<div style="padding: 20px;"> <div style="padding: 20px;">
<h:form> <h:form id="form">
<h:panelGrid columns="2"> <h:panelGrid columns="2">
#{msgs.locationsPrompt} #{msgs.locationsPrompt}
<util:autoComplete value="#{acUser.city}" <util:autoComplete value="#{acUser.city}"
......
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:util="http://java.sun.com/jsf/composite/util"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title>#{msgs.autoCompleteWindowTitle}</title>
</h:head>
<h:body>
<div style="padding: 20px;">
<h:form id="form">
<h:panelGrid columns="2">
#{msgs.locationsPrompt2}
<p:autoComplete id="auto" value="#{acUser.city}"
completeMethod="#{autoComplete.complete}" />
</h:panelGrid>
</h:form>
</div>
<h:button value="#{msgs.home}" outcome="/index"/>
</h:body>
</html>
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
<p><h:link outcome="validation" value="validation"/> </p> <p><h:link outcome="validation" value="validation"/> </p>
<p><h:link outcome="requestMonitor" value="requestMonitor"/> </p> <p><h:link outcome="requestMonitor" value="requestMonitor"/> </p>
<p><h:link outcome="autocomplete" value="autoComplete"/> </p> <p><h:link outcome="autocomplete" value="autoComplete"/> </p>
<p><h:link outcome="pfautocomplete" value="primefaces autocomplete"/> </p>
</h:panelGrid> </h:panelGrid>
</p:panel> </p:panel>
</h:form> </h:form>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment