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

流星永恒的博客

JSF,Facelets,Rich(Prime)Faces,和java的笔记

 
 
 

日志

 
 

JSF 2 with spring 3  

2010-01-04 16:39:41|  分类: jsf2.0 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

       How to integrate jsf 2 with spring 3?

       1. spring jars

        JSF 2 with spring 3 - yyq2007aa - 流星永恒的博客

      2.applicationContext.xml  (copy it to WEB-INF)

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="
http://www.springframework.org/schema/beans"
       xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance"
       xmlns:tx="
http://www.springframework.org/schema/tx"
       xsi:schemaLocation="
      
http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
       http://www.springframework.org/schema/tx
       http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
       http://www.springframework.org/schema/aop
       http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
    ....
   <bean id="userService" parent="serviceMangerTarget"
           class="com.serialssoloutions.service.impl.UserServiceImpl">
    </bean>

   ....

   </beans>

 3. web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="
http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
    <context-param>
        <param-name>javax.faces.PROJECT_STAGE</param-name>
        <param-value>Development</param-value>
    </context-param>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/applicationContext.xml</param-value>
    </context-param>
    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.jsf</url-pattern>
    </servlet-mapping>
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <welcome-file-list>
        <welcome-file>login.jsf</welcome-file>
    </welcome-file-list>
</web-app>

4. faces-config.xml

<faces-config version="2.0"
    xmlns="
http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="
http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd">
<application>
     <variable-resolver>org.springframework.web.jsf.SpringBeanVariableResolver</variable-resolver>
</application>
  <application>
    <el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>
  </application>
</faces-config>

5. jsf bean injecting spring beans

....

import javax.faces.bean.ManagedProperty;

@ManagedBean(name = "loginBean")
@RequestScoped
public class LoginBean {

    private String username;
    private String password;

    @ManagedProperty(value="#{userService}")  //injecting spring bean
    private UserService userService;

    public void setUserService(UserService userService) {
        this.userService = userService;
    }

    public String login() {

        if (username == null || username.trim().length() < 3
                || password == null || password.trim().length() < 6) {
            JSFUtil.addErrorMessage("some check messages");
            return null;
        }
        UserInfo userinfo = null;
        try {
            userinfo = userService.login(username.trim(), password);
            ....
            }
            }

 

If you are a java web developer, that's enough.

  评论这张
 
阅读(1359)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

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

页脚

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