In JSF, you can use the <h:inputSecret /> tag to render a HTML input of type=”password”, password field. For example,

JSF tag…

<h:inputSecret />

Render this HTML code…

<input type="password" name="j_idt6:j_idt7"  />

P.S The name attribute value is randomly generated by JSF.

JSF password example

A full JSF 2 example to render a password input field via <h:inputSecret /> tag.

1. Managed Bean

A simple managed bean, with a “password” property.

package com.mkyong.form;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import java.io.Serializable; @ManagedBean
@SessionScoped
public class UserBean implements Serializable { private String password; public String getPassword() {
return password;
} public void setPassword(String password) {
this.password = password;
} }

2. View Page

Two pages for the demonstration.

demo.xhtml – render a password field via “h:inputSecret”, button via “h:commandButton”, if the button is clicked, password value will be submitted to the “userBean.password’ property via setPassword() method, and forward to “user.xhtml”.

<?xml version="1.0" encoding="UTF-8"?>
<!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://java.sun.com/jsf/html"> <h:body>
<h1>JSF 2 password example</h1> <h:form>
Password : <h:inputSecret value="#{userBean.password}" />
<h:commandButton value="Submit" action="user" />
</h:form> </h:body>
</html>

user.xhtml – display the submitted password value via “h:outputText

<?xml version="1.0" encoding="UTF-8"?>
<!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://java.sun.com/jsf/html"> <h:body>
<h1>JSF 2 password example</h1> Password : <h:outputText value="#{userBean.password}" /> </h:body>
</html>

3. Demo

URL : http://localhost:8080/JavaServerFaces/

Display “demo.xhtml” page

If the button is clicked, display “user.xhtml” page, and also the submitted password value.

JSF 2 password example的更多相关文章

  1. jsf简介

    JSF实现了基于web的以下三个梦想 1.java程序员不必顾虑HTTP的细节,可以按照原本熟悉的事件驱动模型来设计后台系统,并通过一个能担保数据类型无误的数据传递接口将后台系统与前台界面结合在一起. ...

  2. JSF开篇之Login案例

    开发环境:Myeclipse+JDK5+MyEclipse Tomcat+jsf2.2.8 JSF看起来和STRUTS还是有些像的,刚开始还是遇到一点问题:资源包的存放路径及文件访问路径. 开发Log ...

  3. Winter is coming Just have a little faith. JSF框架简介与实例

    JSF 体系结构: JSF 的主要优势之一就是它既是Java Web应用程序的用户界面标准又是严格遵循模型-视图-控制器 (MVC) 设计模式的框架.用户界面代码(视图)与应用程序数据和逻辑(模型)的 ...

  4. 使用netbeans 搭建 JSF+SPRING 框架

    spring版本使用4,jsf版本2.2 jsf的配置文件faces-config.xml <?xml version='1.0' encoding='UTF-8'?> <faces ...

  5. JSF学习五Ajax

    验证username(不能有下划线)和password(不能小于六位) 1.UserBean.java package ajax; import java.io.Serializable; impor ...

  6. JSF标签大全详解

    1. JSF入门 藉由以下的几个主题,可以大致了解JSF的轮廓与特性,我们来看看网页设计人员与应用程序设计人员各负责什么. 1.1简介JSF Web应用程序的开发与传统的单机程序开发在本质上存在着太多 ...

  7. jsf小例子

    有人问我用过jsf没?   当时没有用过,就看了一下: 写了一个小例子  JSF和struts2 差不多的,都有一些配置和跳转 struts2的action配置和JSF的faces-config.xm ...

  8. JSF+EJB+JPA总体思路

    前言: JSF+EJB+JPA 其实我并没有想象中的难,只是想做好,建立在正确的地方应用,真正的困难. 良好的技术,在错误的地方做应用,这是唯一能够被垃圾. 用. 重量级企业应用能够使用这个主要的3层 ...

  9. 【转】JSF中的三大核心组件 UI标签的详细介绍和使用举例

    JSF提供了大量的UI标签来简化创建视图.这些UI标签类似于ASP.NET中的服务器组件.使用这些标签,可以通过其value,binding,action,actionListener等属性直接绑定到 ...

随机推荐

  1. VMware下Ubantu与Windows共享文件夹的方法

    刚刚接触linux的同学往往喜欢在windows系统下安装一个虚拟机,然后在虚拟机上进行操作,但是windows和虚拟机上的linux系统之间的文件互传往往不太方便,今天就总结一个小技巧在window ...

  2. Android手机拍照

    参考的这个视频教程:http://v.youku.com/v_show/id_XNjI5MzkzMjQ4.html和官方API档file:///D:/Android/androidstudio/sdk ...

  3. git for windows+TortoiseGit客户端的使用

        一.安装Git客户端 全部安装均采用默认! 1. 安装支撑软件 : https://code.google.com/p/msysgit/downloads/list?q=full+instal ...

  4. LA 5009 (三分法求极值) Error Curves

    给出的曲线要么是开口向上的抛物线要么是直线,但所定义的F(x)的图形一定是下凸的. 注意一点就是求得是极小值,而不是横坐标,样例也很容易误导人. #include <cstdio> #in ...

  5. JS兼容性问题(FF与IE)

    不同浏览器中js兼容问题大全 1.document.formName.item('itemName')问题 说明: //IE下(两种) document.formName.item("ite ...

  6. ListView 使用

    1. 不使用xml 文件 动态创建 Listview 并且绑定 ArrayList ListView listView = new ListView(this); listView.setAdapte ...

  7. [反汇编练习] 160个CrackMe之020

    [反汇编练习] 160个CrackMe之020. 本系列文章的目的是从一个没有任何经验的新手的角度(其实就是我自己),一步步尝试将160个CrackMe全部破解,如果可以,通过任何方式写出一个类似于注 ...

  8. angular js 实例参数学习

    <!DOCTYPE html> <html> <head> <meta name="description" content=" ...

  9. Android中ListView嵌套进ScrollView时高度很小的解决方案

    package com.example.test.util; import android.view.View; import android.view.ViewGroup; import andro ...

  10. <九>面向对象分析之UML核心元素之设计类,类,属性,方法,可见性

    设计类