AJax技术

AJAX支持的自动填充表单

字号+ 作者: 来源:    2014-11-17 20:43 我要评论( )

AJAX支持的自动填充表单,阅读AJAX支持的自动填充表单,jsf的一个ajax扩展项目, 其实对于使用myfaces的用户来说还有个更的选择:使用MyFaces Sandbox 中的 InputSuggestAjax 用法如下:1.创建一个managed bean: package test;import java.util.ArrayList;import j

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="" prefix="h" %>

<%@ taglib uri="" prefix="f" %>

<%@ taglib uri="" 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

 

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

相关文章
  • 学习AJAX工作原理快速搭建网站方法

    学习AJAX工作原理快速搭建网站方法

    2016-01-17 16:41

  • ajax技术和原理分析

    ajax技术和原理分析

    2016-01-15 08:27

  • AJAX如何与后台交互

    AJAX如何与后台交互

    2016-01-14 14:30

  • 那些年,我还在学习Ajax 学习笔记

    那些年,我还在学习Ajax 学习笔记

    2015-11-22 16:29

网友点评