鍍金池/ 教程/ HTML/ JSF <h:inputText>標簽
JSF數(shù)據(jù)表(h:dataTable)添加刪除
JSF <h:commandLink>標簽
JSF應用程序入門示例
JSF數(shù)據(jù)表(ui:repeat)創(chuàng)建表
JSF列表框
JSF數(shù)據(jù)表(h:dataTable)DataModel排序數(shù)據(jù)
JSF復合組件
JSF <h:inputText>標簽
JSF表單組合框
JSF <h:messages>標簽
JSF <h:message>標簽
JSF轉(zhuǎn)換日期時間
JSF JDBC連接
JSF <h:inputHidden>標簽
JSF多選列表框
JSF <h:inputSecret>標簽
JSF自定義轉(zhuǎn)換器
JSF <f:ajax>標簽
JSF生命周期
JSF可重定位資源
JSFJSF用戶界面組件模型
JSF <h:attribute>標簽
JSF驗證器標簽
JSF驗證字符串長度
JSF轉(zhuǎn)換器標簽
JSF托管bean(Managed Bean)
JSF值變化的事件
JSF UI組件示例
JSF MySQL CURD實例
JSF數(shù)據(jù)表(h:dataTable)排序數(shù)據(jù)
JSF <h:graphicImage>標簽
JSF <f:convertNumber>標簽
JSF教程
JSF托管Bean
JSF輸出腳本
JSF <h:outputText>標簽
JSF操作事件
JSF驗證正則表達式
JSF數(shù)據(jù)表(h:dataTable)行號
JSF <h:setPropertyActionListener>標簽
JSF注入托管bean實例
JSF <h:commandButton>標簽
JSF Web資源
JSF <h:inputFile>標簽
JSF驗證浮點數(shù)值范圍
JSF Facelets視圖
JSF是什么?
JSF Facelets模板
JSF的特性(特點)
JSF自定義驗證器類
JSF單選按鈕
JSF輸出樣式
JSF數(shù)據(jù)表(h:dataTable)更新數(shù)據(jù)
JSF HTML5友好標記
JSF表單復選框(CheckBox)示例
JSF <h:form>標簽
JSF Facelets技術(shù)介紹
JSF輸出格式化
JSF <h:inputtextarea>標簽
JSF驗證整數(shù)范圍
JSF <h:panelGrid>標簽

JSF <h:inputText>標簽

JSF <h:inputText>標簽用于呈現(xiàn)網(wǎng)頁上的輸入字段。它在<h:form>標簽中用于聲明允許用戶輸入數(shù)據(jù)的輸入字段。

value屬性指的是名為User的委托Beanname屬性。該屬性保存名稱組件的數(shù)據(jù)。 用戶提交表單后,User中的name屬性的值將被設置為與該標簽對應的字段中輸入的文本。

打開 NetBean8.2,創(chuàng)建一個名稱為:htags的JSF工程,然后按以下步驟添加相應文件和代碼。

JSF <h:InputText>標簽示例

在下面的示例中,我們使用標簽標簽為inputText標簽提供標簽,一個帶有屬性的inputText,一個用于表示提交按鈕的commandButton。 全部都被包含在<h:form>標簽中。

文件: inputtext.xhtml 的代碼如下所示 -

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html">
    <h:head>
        <title>Facelet Title</title>
    </h:head>
    <h:body>
        <h:form id="form">  
            <h:inputText id="username" value="#{user.name}" label="username" maxlength="10"            
                         size="15" alt="username" autocomplete="off" readonly="false" required="true"              
                         requiredMessage="Username is required" style="color:red" accesskey="q">  
            </h:inputText>   </h:form>
    </h:body>
</html>

2)創(chuàng)建托管Bean

文件: User.java 的代碼如下所示 -

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.yiibai;

/**
 *
 * @author Maxsu
 */
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;

@ManagedBean
@RequestScoped
public class User {

    String name;
    String email;
    String password;
    String gender;
    String address;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }
}

JSF渲染<h:inputText>標簽如下:

代碼如下所示 -

<input id="userform:username" name="userform:username" autocomplete="off" accesskey="q"   
alt="username" maxlength="10" size="15" style="color:red" type="text">

4)運行應用程序

打開瀏覽器,訪問:http://localhost:8084/htags/faces/inputtext.xhtml , 輸出如下所示 -

JSF <h:inputText> 標簽的屬性

屬性名稱 描述
id 它是此組件的標識符,ID必須是唯一的。您可以使用它來訪問CSS和JS文件中的HTML元素。
value 它用于收集輸入文本的當前值。
class 它給組件的類名,它用于從CSS和JS文件訪問組件。
maxlength 在此字段中可能輸入的最大字符數(shù)。
alt 由該組件呈現(xiàn)的元素的替代文本描述。
accesskey 按鍵的訪問鍵將焦點轉(zhuǎn)移到該元素。它將根據(jù)瀏覽器的不同而不同。
size 用于確定此字段寬度的字符數(shù)。
required 它表示用戶需要為此輸入組件提供提交的值。
requiredMessage 如果將required屬性設置為true,則在“RequiredMessage”中提供的消息描述將顯示到網(wǎng)頁。
style 它用于為組件應用CSS。
rendered 它用于渲染組件。該屬性的默認值為true。
convertor 它用于注冊此組件的轉(zhuǎn)換器實例。
readonly 它表示該組件禁止用戶進行更改,通過將readonly作為此屬性的值傳遞,可以使組件只讀。 例如。 readonly =“readonly”