注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

阿弥陀佛

街树飘影未见尘 潭月潜水了无声 般若观照心空静...

 
 
 

日志

 
 
关于我

一直从事气象预报、服务建模实践应用。 注重气象物理场、实况场、地理信息、本体知识库、分布式气象内容管理系统建立。 对Barnes客观分析, 小波,计算神经网络、信任传播、贝叶斯推理、专家系统、网络本体语言有一定体会。 一直使用Java、Delphi、Prolog、SQL编程。

网易考拉推荐

JSF模板测试代码  

2012-02-15 18:09:12|  分类: JavaServer Faces |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

"/temp/lnf-template.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:ui="http://java.sun.com/jsf/facelets">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <title><ui:insert name="title">Placeholder Title</ui:insert></title>
        <!--link href="http://hxfcalf.blog.163.com/blog/css/vt.css" rel="stylesheet" media="screen" /-->
    </head>
    <body>
        <table width="100%" border="0">
            <tr>
                <td height="89">
                    <h1 align="center">
                        <img src="http://hxfcalf.blog.163.com/blog/images/logo.JPG" width="92"
                             height="110" />JSF Virtual Trainer Application</h1>
                </td>
            </tr>
            <tr>
                <ui:insert name="body">Placeholder Body</ui:insert>
            </tr>
        </table>
    </body>
</html>

register.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:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core">
    <body>

        <ui:composition template="/temp/lnf-template.xhtml">
            <ui:define name="title">
                JavaServer Faces Virtual Trainer Application
                Registration </ui:define>
            <ui:define name="body">
                <h:form>
                    <table width="70%">
                        <tr>
                            <td width="40%">First Name:</td>
                            <td width="60%">
                                <input type="text" jsfc="h:inputText" required="true"
                                       id="fname"
                                       value="#{UserBean.firstname}" />
                                <h:message for="fname"/>
                            </td>
                        </tr>
                        <tr>
                            <td width="40%">Last Name:</td>
                            <td width="60%">
                                <input type="text" jsfc="h:inputText"
                                       value="#{UserBean.lastname}" required="true"
                                       id="lname" />
                                <h:message for="lname"/>
                                <span jsfc="h:message" for="fname">Message</span>
                            </td>
                        </tr>
                        <tr>
                            <td width="40%">Gender:</td>
                            <td width="60%">
                                <h:selectOneRadio type="radio"
                                                  value="#{UserBean.gender}" required="true" id="gender">
                                    <input type="radio" jsfc="f:selectItem"
                                           itemLabel="Male" itemValue="male" />
                                    <input type="radio" jsfc="f:selectItem"
                                           itemLabel="Female" itemValue="female" />
                                </h:selectOneRadio>
                                <h:message for="gender"/>
                            </td>
                        </tr>
                        <tr>
                            <td width="40%">Date of Birth:</td>
                            <td width="60%">
                                <h:inputText value="#{UserBean.dob}" id="dob" required="true" >
                                    <f:convertDateTime pattern="mm-dd-yy"/>
                                </h:inputText>(mm-dd-yy)
                                <h:message for="dob"/> </td>
                        </tr>
                        <tr>
                            <td width="40%">Email Address:</td>
                            <td width="60%">
                                <h:inputText value="#{UserBean.email}" required="true"
                                             validator="#{UserBean.validateEmail}" id="email"/>
                                <h:message for="email"/>
                            </td>
                        </tr>
                        <!-- Remainder of rows deleted for brevity -->
                    </table>
                    <p><h:messages /></p>
                    <p><h:commandButton value="Register" action="confirm" /></p>
                </h:form>
            </ui:define>
        </ui:composition>
    </body>
</html>
UserBean.java
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bean;

import java.util.Date;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.validator.ValidatorException;

@ManagedBean
@SessionScoped
public class UserBean {

    protected String firstName;
    protected String lastName;
    protected Date dob;
    protected String sex;
    protected String email;
    protected String serviceLevel = "medium";

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public Date getDob() {
        return dob;
    }

    public void setDob(Date dob) {
        this.dob = dob;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public String getEmail() {
        return email;
    }

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

    public String getServiceLevel() {
        return serviceLevel;
    }

    public void setServiceLevel(String serviceLevel) {
        this.serviceLevel = serviceLevel;
    }

    public void validateEmail(FacesContext context,
            UIComponent toValidate,
            Object value) throws ValidatorException {
        String emailStr = (String) value;
        if (-1 == emailStr.indexOf("@")) {
            FacesMessage message = new FacesMessage("Invalid emailaddress");
            throw new ValidatorException(message);
        }
    }

    public String addConfirmedUser() {
        boolean added = true; // actual application may fail to add user
        FacesMessage doneMessage = null;
        String outcome = null;
        if (added) {
            doneMessage = new FacesMessage("Successfully added new user");
            outcome = "done";
        } else {
            doneMessage = new FacesMessage("Failed to add new user");
            outcome = "register";
        }
        FacesContext.getCurrentInstance().addMessage(null, doneMessage);
        return outcome;
    }
}
  评论这张
 
阅读(762)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017