AJAX支援的自動填滿表單

來源:互聯網
上載者:User

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

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.