技术开发 频道

快速上手:MyEclipse下开发JSF


IT168技术文档】 
    三. 创建Message Bundle
    Message Bundle文件是一个简单的属性文件,存储与keys相关的消息,提供国际化支持,也可以用在JSP页面中。Struts也提供了类似的文件ApplicationResources.properties。 

    在JSF中,可以在页面中加载message bundle使用如下代码:<f:loadBundle basename="com.jsfdemo.MessageBundle" var= "bundle"/> 
    在创建message bundle文件之前,在src文件中通过右键选择“New > Package”来创建com.jsfdemo包。使用新键文件向导来创建message bundle文件,如图3.1:


    Figure 3.1: Creating the Message Bundle file 

    创建完MessageBundle.properties文件以后,要添加在JSP页面显示的每个标签的key/value对或者是文本字符串。可以复制下面中的内容到message bundle文件中。 
    MessageBundle.properties 
    user_name_label=User Name: 
    user_password_label=Password: 
    login_button_label=Login 

    MessageBundle.properties文件的内容 

    MessageBundle文件创建完以后,下一步,我们要创建ManagedBean以处理用户登录。 

    四. 创建 Managed Beans 
    这部分我们将创建Managed Beans来执行login操作,在这个Demo中,登录操作就是简单的核对用户名和密码是否都是myeclipse,并将页面转向到userLoginSuccess.jsp。 

    首先用MyEclipse JSF Editor打开faces-config.xml文件



    Figure 4.1: Opening faces-config.xml file for editing 
    点击右上角的Add ManagedBean来添加新的bean,如图所示:


    Figure 4.2: Launch the ManagedBean wizard from the Outline View 
    点击以后出现新的Managed Bean向导,如图所示添加值


    Figure 4.3: Setup the new ManagedBean's class and properties


    Figure 4.4: Managed Bean Wizard Final Page
0
相关文章