|
|
|
<html>
<head>
<meta http-equiv=”Content-Type” content=”text/html;
charset=iso-8859-1">
<title>JSF Auto Complete Example</title>
<style type=”text/css”>
body{
margin-top:30px;
margin-bottom:opx;
margin-left:0px;
margin-right:0px;
}
</style>
</head>
<body>
<center>
<h:panelGrid id=”pg1" columns=”1" width=”500px”
style=”background-image:url(images/border2.gif)”>
<f:facet name=”header”>
<h:outputText value=”JSF Autocomplet Example”/>
</f:facet>
</h:panelGrid>
<h:form>
</br>
<h:outputText value=”Enter U.S State:” style=”font-weight:bold”
/>
<s:inputSuggestAjax
suggestedItemsMethod=”#{StateBean.getSuggestItems}”
value=”#{StateBean.currentValue}” />
</h:form>
<h:graphicImage id=”gi2" value=”images/border.gif”
width=”500px” height=”74">
</h:graphicImage>
</center>
</body>
</html>
</f:view>
To use the tag for the component, we have to specify
the name of tag library with prefix. We have specified
prefix “s” for the sandbox tags. Now we can use the
components of sandbox in our JSP file. In this example,
we have used only one component “inputSuggestAjax”.
It has “suggestedItemsMethod” attribute which has
been set to the property “getSuggestItems” of backing
bean StateBean. This bean provides set of states to be
displayed when user enters some words of the state. The
current value of the component is set to the property
“currentValue” of the same bean.
Creating Managed Bean:
|
|
package net.roseindia.web.ui;
import java.util.*;
public class StateBean{
String currentValue;
public String getCurrentValue() {
return currentValue;
}
public void setCurrentValue(String currentValue)
{
this.currentValue = currentValue;
}
public List getSuggestItems(String prefix)
{
List list = new ArrayList();
list.add(“Alabama”);
list.add(“Alaska”);
list.add(“Arizona”);
list.add(“Arkansas”);
list.add(“California”);
list.add(“Colorado”);
list.add(“Connecticut”);
list.add(“Delaware”);
list.add(“District of Columbia”);
list.add(“Florida”);
list.add(“Georgia”);
list.add(“Hawaii”);
list.add(“Idaho”);
list.add(“Illinois”);
list.add(“Indiana”);
list.add(“Iowa”);
list.add(“Kansas”);
list.add(“Kentucky”);
list.add(“Louisiana”);
list.add(“Maine”);
list.add(“Maryland”);
list.add(“Massachusetts”);
list.add(“Michigan”);
list.add(“Minnesota”);
list.add(“Mississippi”);
list.add(“Missouri”);
list.add(“Montana”);
list.add(“Nebraska”);
list.add(“Nevada”);
list.add(“New Hampshire”);
list.add(“New Jersey”);
list.add(“New Mexico”);
list.add(“New York”);
list.add(“North Carolina”);
list.add(“North Dakota”);
list.add(“Ohio”);
list.add(“Oklahoma”);
list.add(“Oregon”);
list.add(“Pennsylvania”);
list.add(“Rhode Island”);
list.add(“South Carolina”);
list.add(“South Dakota”);
list.add(“Tennessee”);
list.add(“Texas”);
list.add(“Utah”); |
|
August 2007 | Java Jazz Up | 16 |
|
|
|
Pages: 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, |
31, 32, 33, 34, 35, 36, 37, 38, 39, 40 Download PDF |
|
|
|
|
|
|
|
|