all gone

all gone

Eclipse下JSF入门

1.开发环境
   与Eclipse下Struts的开发类似,安装好Eclipse和Tomcat之后,还需要两个插件:tomcat 插件和JSF插件(如果相关插件还没有安装),以下是相关下载地址:
    Eclipse SDK:
        http://www.eclipse.org/downloads/index.php 
    JSF:
     https://sourceforge.jp/projects/amateras/files/  
      FaceIDE+htmlEditor,htmlEditer也是必要的
    Tomcat :
         http://www.sysdeo.com/eclipse/tomcatplugin 
    Plugin Search:
         http://eclipse-plugins.2y.net/eclipse/search.jsp 
   插件的安装和配置有问题请直接Google。
2.开始
    入门嘛,我们就找一个最简单的Login就可以了

    新建Tomcat project
    加入JSF支持

    新建一个ManagedBean:


/**
 *
 */
package com.jsf;




/**
 * @author lzy
 *
 */
public class UserBean {
private String name;
    private String password;
public String verify() {
     if(this.name.equals("name")&&this.password.equals("password"))
     
        return "failure";

   else
        return "success";
}

 
/**
* @return Returns the name.
*/
public String getName() {
return name;
}

/**
* @param name The name to set.
*/
public void setName(String name) {
this.name = name;
}


/**
* @return Returns the password.
*/
public String getPassword() {
return password;
}

/**
* @param password The password to set.
*/
public void setPassword(String password) {
this.password = password;
}


}

     新建两个JSP页面,login.jsp,welcom.jsp

login.jsp
<%@ page contentType="text/html; charset=GBK" %>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>

<html>
<head>
<%@ page contentType="text/html; charset=GBK" %>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>

<html>
<head>
<link href="main.css" rel="stylesheet"/>
<title></title>

</head>
<body>
    <f:view>
    <f:loadBundle basename="com.jsf.MessageResources" var="msgs"></f:loadBundle>
   
        <h:form>
        <h:panelGrid columns="3" headerClass="header" rowClasses="evenRow,oddRow">
        <f:facet name="header" >
        <h:outputText value="#{msgs.header}"/>
        </f:facet>
       
        <h:outputText value="#{msgs.namePromt}"></h:outputText>
        <h:inputText id="name"  required="true" value="#{user.name}">
        <f:validateLength minimum="2" maximum="10"></f:validateLength>
        </h:inputText>
        <h:message for="name" errorClass="errors"/>
       
       
        <h:outputText value="#{msgs.passwordPromt}"></h:outputText>
       
        <h:inputSecret id="password" value="#{user.password}" required="true" redisplay="true">
        <f:validateLength minimum="2"></f:validateLength>
        </h:inputSecret>
        <h:message for="password"/>
       
       
              <f:facet name="footer" >
        <h:outputText value="#{msgs.footer}"/>
        </f:facet>
        </h:panelGrid>          
            <h:commandButton value="#{msgs.submitPromt}" action="#{user.verify}"/>
            <h:commandButton value="#{msgs.resetPromt}" type="reset"/>
        </h:form>
    </f:view>
</body>
</html>



welcome.jsp


<%@ page contentType="text/html; charset=GBK" %>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK"/>
<title></title>
</head>
<body>
    <f:view>
        <h:outputText value="#{user.name}"/>  is a good boy!
        <h3>welcome JavaServer Faces</h3>
    </f:view>
</body>

</html>
     编辑WEB-INF/lib下的faces-config.xml

struts-config.xml

<?xml version="1.0"?>
<!DOCTYPE faces-config PUBLIC "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN" "http://java.sun.com/dtd/web-facesconfig_1_1.dtd">
<faces-config>
<navigation-rule>
        <from-view-id>/login.jsp</from-view-id>
        <navigation-case>
            <from-outcome>success</from-outcome>
            <to-view-id>/welcome.jsp</to-view-id>
        </navigation-case>
        <navigation-case>
            <from-outcome>failure</from-outcome>
            <to-view-id>/login.jsp</to-view-id>
        </navigation-case>
</navigation-rule>


<managed-bean>
<managed-bean-name>user</managed-bean-name>
<managed-bean-class>com.jsf.UserBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
</faces-config>


       最后是资源文件

# --login.jsp--
header=Welcom
namePromt=Name:
passwordPromt=Password:
amountPromt=Amount:
datePromt=Date:
submitPromt=Submit
resetPromt=Reset
footer=Thank you!


3.测试
在test工程中选择tomcat project->Update context definition
然后运行Tomcat
http://127.0.0.1:8080/jsfTest/login.jsf

posted on 2005-12-10 12:05 all gone 阅读(17604) 评论(11)  编辑  收藏 所属分类: Java

评论

# re: Eclipse下JSF入门 2007-01-11 10:10 小鸟[匿名]

login.jsp
怎么两个
<%@ page contentType="text/html; charset=GBK" %>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>


MessageResources.prxxxxx 放在哪进里???


俺试了,,漏洞百出,,,

不好意思,俺今天才接触jsf.....  回复  更多评论   

# re: Eclipse下JSF入门 2007-01-12 18:28 all gone[匿名]

# --login.jsp-- 是在资源文件里的
表示这是在login.jsp中用到的

肯定只会有一个login.jsp  回复  更多评论   

# re: Eclipse下JSF入门 2007-08-10 08:31 few

https://sourceforge.jp/projects/amateras/files
-----------
楼主给个日文的链接,是在卖弄吗?  回复  更多评论   

# re: Eclipse下JSF入门 2007-08-31 00:43 hello

楼上的不懂不要乱说。

只有日文的。  回复  更多评论   

# re: Eclipse下JSF入门[未登录] 2007-09-14 15:39 kevin

呵呵,笑死了。日文连接。你不还给个中文的,我也没看懂啊。下来试试的。  回复  更多评论   

# re: Eclipse下JSF入门[未登录] 2007-09-14 15:42 kevin

myeclipse里面都有,有区别吗?  回复  更多评论   

# re: Eclipse下JSF入门 2008-04-10 14:32 鹅鹅鹅

小破程序员还挺爱国,还抗日
这哥们应该早生70年  回复  更多评论   

# re: Eclipse下JSF入门 2008-10-29 18:56 sfd

就没有自动写发faces-config.xml文件嘛  回复  更多评论   

# re: Eclipse下JSF入门 2009-01-13 11:05 飞雪、

日文的里面点美国国旗应该就都是英文了吧,除了广告图片!  回复  更多评论   

# re: Eclipse下JSF入门[未登录] 2009-03-17 20:50 躺着读书

我也爱日本 咋了

但是我还是给一个elipse for j2ee的官方版本的jsf环境设置教程。
http://www.eclipse.org/webtools/jsf/docs/tutorial/JSFTools_1_0_tutorial.html

eclipse官方是内置了对于jsf的支持的,只是默认这个功能没有打开。需要配置。新建项目后转到内置web程序的视图。比netbeans 好多了。  回复  更多评论   

# re: Eclipse下JSF入门 2009-07-27 20:51 fuck japan

fuck japan  回复  更多评论   


只有注册用户登录后才能发表评论。


网站导航: