AJAX支持的自动填充表单

<script type="text/JavaScript"> </script> <script src="http://a.alimama.cn/inf.js" type="text/javascript"> </script>

 

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

 4. 输出页面:

效果图

版本为   1.1.4 示例代码

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值