Java EE 6 和Rational Application Developer 8(RAD8)系列-JSF 2.0简单例子

本文展示了使用Rational Application Developer 8 (RAD8) 和 Java EE 6 进行 JSF 应用开发的过程。通过两个 XHTML 页面和一个 Managed Bean 的实现,演示了用户输入收集与反馈的基本交互。

Rational Application Developer 8(RAD8)出来之后,试了一下《 Java EE 6 导学》中的JSF例子,下面的截图和代码。

 

WebSphere Applications Server 测试环境运行效果图

 

 

 

 

 

Rational Application Developer 8(RAD8)图形化设计关键界面

 

 

 

 

 

 

页面代码和managed bean 代码

 

 

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html">
<h:head>
    <title>Facelets Hello Greeting</title>
</h:head>
<h:body>
    <h:form>
        <h2>Hello, my name is ChinaJava.net. What’s yours?</h2>
        <h:inputText id="username"
        value="#{hello.name}"
        required="true"
        requiredMessage="A name is required."
        maxlength="25">
        </h:inputText>
        <p></p>
        <h:commandButton id="submit" value="Submit" action="response1">
        </h:commandButton>
        <h:commandButton id="reset" value="Reset" type="reset">
        </h:commandButton>
    </h:form>
</h:body>
</html>

 

-----------------------------------------------------

 

response1.xhtml

 

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html">
<h:head>
<title>Facelets Hello Response</title>
</h:head>
<h:body>
<h:form>
<h2>Hello, #{hello.name}!</h2>
<p></p>
<h:commandButton id="back" value="Back" action="index1" />
</h:form>
</h:body>
</html>

 

-----------------------------------------------

 

package hello1;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;

@ManagedBean
@RequestScoped
public class Hello {
    private String name;

    public Hello() {
    }

    public String getName() {
        return name;
    }

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

 

 

 


 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值