点击这里给我发消息 点击这里给我发消息

AJAX支持的自动填充表单

添加时间:2010-1-5
    相关阅读: 页面 项目

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

本文作者:
咨询热线:020-85648757 85648755 85648616 0755-27912581 客服:020-85648756 0755-27912581 业务传真:020-32579052
广州市网景网络科技有限公司 Copyright◎2003-2008 Veelink.com. All Rights Reserved.
广州商务地址:广东省广州市黄埔大道中203号(海景园区)海景花园C栋501室
= 深圳商务地址:深圳市宝源路华丰宝源大厦606
研发中心:广东广州市天河软件园海景园区 粤ICP备05103322号 工商注册