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

阿弥陀佛

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

 
 
 

日志

 
 
关于我

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

网易考拉推荐

JSF Flash在Master/Detail中的测试  

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

  下载LOFTER 我的照片书  |

<?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"
      xmlns:f="http://java.sun.com/jsf/core">
    <h:head>
        <title>A Simple JavaServer Faces 2.0 View</title>
    </h:head>
    <h:body>
        <h:form>
            <h1>Master</h1>
            <p><h:selectOneMenu value="#{flash.serviceLevel}">
                    <f:selectItems value="#{model.keys}"/>
                </h:selectOneMenu>
                <h:commandButton value="Show Subscribers" /></p>
        </h:form>
        <h:panelGroup rendered="#{! empty flash.serviceLevel}">
            <h1>Detail</h1>
            <p>Users with Service Level: "#{flash.serviceLevel}":</p>
            <h:dataTable border="1" var="user"
                         value="#{model.data[flash.serviceLevel]}">
                <h:column>
                    <f:facet name="header">First Name</f:facet>
                    #{user.firstName}
                </h:column>
                <h:column>
                    <f:facet name="header">Last Name</f:facet>
                    #{user.lastName}
                </h:column>
                <h:column>
                    <f:facet name="header">Sex</f:facet>
                    #{user.sex}
                </h:column>
            </h:dataTable>
        </h:panelGroup>
    </h:body>
</html>

/*
 * 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;
    }
}
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bean;

import java.util.*;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

@ManagedBean
@SessionScoped
public class Model {

    private Map<String, List<UserBean>> data;

    public Model() {
        data = new HashMap<String, List<UserBean>>();
// Populate the model with data in the constructor. Naturally
// in a real application, the model would be populated some
// other way
        List<UserBean> users = new ArrayList<UserBean>();
// users with "Medium" service level
        users.add(makeUser("Bob", "Biceps", "Medium", "M"));
        users.add(makeUser("Frank", "Forearms", "Medium", "M"));
        users.add(makeUser("Sherry", "Shins", "Medium", "F"));
        users.add(makeUser("Alice", "Abs", "Medium", "F"));
        data.put(users.get(0).getServiceLevel(), users);
        users = new ArrayList<UserBean>();
// users with "Basic" service level
        users.add(makeUser("Pete", "Pectorals", "Basic", "M"));
        users.add(makeUser("Neil", "Neck", "Basic", "M"));
        users.add(makeUser("Ellen", "Elbows", "Basic", "F"));
        users.add(makeUser("Tina", "Tummy", "Basic", "F"));
        data.put(users.get(0).getServiceLevel(), users);
        users = new ArrayList<UserBean>();
// users with "Premium" service level
        users.add(makeUser("Bernd", "Beine", "Premium", "M"));
        users.add(makeUser("Rolf", "Rückenschmerz", "Premium", "M"));
        users.add(makeUser("Bettina", "Bauch", "Premium", "F"));
        users.add(makeUser("Frauke", " Fu?kn?chel", "Premium", "F"));
        data.put(users.get(0).getServiceLevel(), users);
    }

    public Set<String> getKeys() {
        return data.keySet();
    }

    private UserBean makeUser(String firstName, String lastName,
            String serviceLevel, String sex) {
        UserBean result = new UserBean();
        result.setFirstName(firstName);
        result.setLastName(lastName);
        result.setServiceLevel(serviceLevel);
        result.setSex(sex);
        return result;
    }

    public Map<String, List<UserBean>> getData() {
        return data;
    }
}
  评论这张
 
阅读(779)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

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

页脚

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