Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Bruce Link
ch10-ajax
Commits
3d1af859
Commit
3d1af859
authored
Nov 25, 2020
by
Bruce Link
Browse files
added primefaces autocomplete example
parent
e1c307e5
Changes
6
Hide whitespace changes
Inline
Side-by-side
src/main/java/com/corejsf/autocomplete/AutoComplete.java
View file @
3d1af859
package
com.corejsf.autocomplete
;
import
java.io.Serializable
;
import
java.util.ArrayList
;
import
java.util.List
;
import
javax.inject.Named
;
import
javax.enterprise.context.ApplicationScoped
;
...
...
@@ -8,36 +10,51 @@ import javax.enterprise.context.ApplicationScoped;
@Named
@ApplicationScoped
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
()
{
return
new
String
[]
{
"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"
};
return
locations
;
}
public
List
<
String
>
complete
(
String
query
)
{
System
.
out
.
println
(
"autoComplete.complete("
+
query
+
")"
);
String
lcQuery
=
query
.
toLowerCase
();
List
<
String
>
result
=
new
ArrayList
<
String
>();
for
(
String
s
:
locations
)
{
if
(
s
.
toLowerCase
().
startsWith
(
lcQuery
))
{
result
.
add
(
s
);
}
}
return
result
;
}
}
src/main/resources/messages.properties
View file @
3d1af859
autoCompleteWindowTitle
=
JSF 2 Ajax
locationsPrompt
=
Locations
locationsPrompt2
=
PrimefacesLocations
loginWindowTitle
=
JSF 2 Ajax
loginHeading
=
Please Log In
namePrompt
=
Name:
...
...
src/main/webapp/WEB-INF/faces-config.xml
View file @
3d1af859
...
...
@@ -35,4 +35,10 @@
<to-view-id>
/autocomplete/index.xhtml
</to-view-id>
</navigation-case>
</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>
\ No newline at end of file
src/main/webapp/autocomplete/index.xhtml
View file @
3d1af859
...
...
@@ -3,14 +3,15 @@
"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: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>
<h:form
id=
"form"
>
<h:panelGrid
columns=
"2"
>
#{msgs.locationsPrompt}
<util:autoComplete
value=
"#{acUser.city}"
...
...
src/main/webapp/autocomplete/indexPrimefaces.xhtml
0 → 100644
View file @
3d1af859
<?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>
src/main/webapp/index.xhtml
View file @
3d1af859
...
...
@@ -20,6 +20,7 @@
<p><h:link
outcome=
"validation"
value=
"validation"
/>
</p>
<p><h:link
outcome=
"requestMonitor"
value=
"requestMonitor"
/>
</p>
<p><h:link
outcome=
"autocomplete"
value=
"autoComplete"
/>
</p>
<p><h:link
outcome=
"pfautocomplete"
value=
"primefaces autocomplete"
/>
</p>
</h:panelGrid>
</p:panel>
</h:form>
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment