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

added primefaces autocomplete example

parent e1c307e5
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,8 +10,7 @@ import javax.enterprise.context.ApplicationScoped;
@Named
@ApplicationScoped
public class AutoComplete implements Serializable {
public String[] getLocations() {
return new String[] {
String[] locations = {
"Abbotsford", "Agassiz", "Albuquerque", "Aldergrove", "Arvada", "Ashcroft",
"Bahamas", "Baltimore", "Bamfield", "Bayou", "Belgrade", "Bella Coola",
"Boston Bar", "Boulder", "Brighton","Brittany", "Buffalo", "Burnaby",
......@@ -39,5 +40,21 @@ public class AutoComplete implements Serializable {
"Vail", "Valdes Island", "Vancouver", "Vernon", "Victoria",
"Watson Lake", "West Vancouver", "Whistler", "Williams Lake", "Windermere"
};
public String[] getLocations() {
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;
}
}
autoCompleteWindowTitle=JSF 2 Ajax
locationsPrompt=Locations
locationsPrompt2=PrimefacesLocations
loginWindowTitle=JSF 2 Ajax
loginHeading=Please Log In
namePrompt=Name:
......
......@@ -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
......@@ -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}"
......
<?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 @@
<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>
......
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