当前位置:首页 > 设计在线 > 网页设计 > Javascript > AJAX支持的自动填充表单

AJAX支持的自动填充表单

点击次数:27 次 发布日期:2008-11-26 23:17:54 作者:源代码网
源代码网推荐 jsf的一个Ajax扩展项目, 其实对于使用myfaces的用户来说还有个更的选择:使用MyFaces Sandbox 中的 InputSuggestAjax   用法如下:

源代码网整理以下1.创建一个managed bean:

源代码网整理以下package test;

源代码网整理以下import java.util.ArrayList;

源代码网整理以下import java.util.List;

源代码网整理以下public class Bean {    

源代码网整理以下            //In that function all what you had to do is to

源代码网整理以下            //Specify what will be displayed in the list

源代码网整理以下            //Note that the keyword is the text entered by the user

源代码网整理以下            public List getSuggestedWords(String keyword) {

源代码网整理以下                        List list = new ArrayList();

源代码网整理以下                        list.add(keyword + " Ahmed Saleh");

源代码网整理以下                        list.add(keyword + " Kahki");

源代码网整理以下                        list.add(keyword + " Kourany");

源代码网整理以下                        list.add(keyword + " Kiki");

源代码网整理以下                        list.add(keyword + " Saleh Abouetta");

源代码网整理以下                        list.add(keyword + " Hashim");

源代码网整理以下                        return list;

源代码网整理以下            }

源代码网整理以下            public String getCurrentValue() {

源代码网整理以下                        return currentValue;

源代码网整理以下            }
            public void setCurrentValue(String currentValue) {

源代码网整理以下                        this.currentValue = currentValue;

源代码网整理以下            }
            String currentValue;

源代码网整理以下}

源代码网整理以下2.     jsp 页面代码

源代码网整理以下<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>

源代码网整理以下<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>

源代码网整理以下<%@ taglib uri="http://myfaces.apache.org/sandbox" prefix="s" %>

源代码网整理以下<html>

源代码网整理以下<head>

源代码网整理以下<title>Ajax JSF sample (InputSuggestAjax)</title>

源代码网整理以下</head>

源代码网整理以下<body>

源代码网整理以下<f:view>

源代码网整理以下 <h:form>

源代码网整理以下  <h:outputText value="Enter your name : "/>

源代码网整理以下   <s:inputSuggestAjax suggestedItemsMethod="#{bean.getSuggestedWords}"

源代码网整理以下    value="#{bean.currentValue}" />

源代码网整理以下   <br />

源代码网整理以下   <h:commandButton action="" value="Submit"/>

源代码网整理以下   <br />

源代码网整理以下   <h:outputText value="Your name is #{bean.currentValue}"/>

源代码网整理以下 </h:form>

源代码网整理以下</f:view>

源代码网整理以下</body>    

源代码网整理以下</html> 

源代码网整理以下 3.  web.xml配置

源代码网整理以下<context-param>

源代码网整理以下  <param-name>javax.faces.STATE_SAVING_METHOD</param-name>

源代码网整理以下  <param-value>client</param-value>

源代码网整理以下</context-param>

源代码网整理以下//Instead of server make the state saving method on the client to make it works


源代码网供稿.
网友评论 (0)
会员中心
设计在线
本站推荐
设计在线之精华