JSF和Spring集成2--简单配置

web.xml配置:

<? xml version="1.0" ?>

<!--
 * Copyright 2004 The Apache Software Foundation.
 *
 * Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an &quot;AS IS&quot; BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 
 
-->

<! DOCTYPE web-app PUBLIC
  "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
  "http://java.sun.com/dtd/web-app_2_3.dtd"
>

< web-app >
 
< servlet >
  
< servlet-name > Faces Servlet </ servlet-name >
  
< servlet-class > javax.faces.webapp.FacesServlet </ servlet-class >
 
</ servlet >
 
< context-param >
  
< param-name > contextConfigLocation </ param-name >
  
< param-value > /WEB-INF/applicationContext.xml </ param-value >
 
</ context-param >
 
< context-param >
  
< param-name > javax.faces.CONFIG_FILES </ param-name >
  
< param-value > /WEB-INF/faces-components-config.xml,/WEB-INF/faces-navigation-config.xml </ param-value >
  
< description > Comma separated list of URIs of (additional) faces config files. (e.g. /WEB-INF/my-config.xml) See JSF 1.0 PRD2, 10.3.2 </ description >
 
</ context-param >

 
< context-param >
  
< param-name > javax.faces.STATE_SAVING_METHOD </ param-name >
  
< param-value > client </ param-value >
 
</ context-param >
 
< context-param >
  
< param-name > myfaces_allow_javascript </ param-name >
  
< param-value > true </ param-value >
 
</ context-param >

 
< context-param >
  
< param-name > org.apache.myfaces.ALLOW_JAVASCRIPT </ param-name >
  
< param-value > true </ param-value >
  
< description >
   This parameter tells MyFaces if javascript code should be allowed in the rendered HTML output. If javascript is allowed, command_link anchors will have javascript code that submits the corresponding form. If javascript is not allowed, the state
   saving info and nested parameters will be added as url parameters. Default: 
&quot; true &quot;
  
</ description >
 
</ context-param >

 
< context-param >
  
< param-name > org.apache.myfaces.DETECT_JAVASCRIPT </ param-name >
  
< param-value > false </ param-value >
  
< description >
   This parameter tells MyFaces if javascript code should be allowed in the rendered HTML output. If javascript is allowed, command_link anchors will have javascript code that submits the corresponding form. If javascript is not allowed, the state
   saving info and nested parameters will be added as url parameters. Default: 
&quot; false &quot;

   Setting this param to true should be combined with STATE_SAVING_METHOD 
&quot; server &quot;  for best results.

   This is an EXPERIMENTAL feature. You also have to enable the detector filter/filter mapping below to get JavaScript detection working.
  
</ description >
 
</ context-param >

 
< context-param >
  
< param-name > org.apache.myfaces.PRETTY_HTML </ param-name >
  
< param-value > true </ param-value >
  
< description > If true, rendered HTML code will be formatted, so that it is  &quot; human readable &quot; . i.e. additional line separators and whitespace will be written, that do not influence the HTML code. Default:  &quot; true &quot; </ description >
 
</ context-param >
 
< context-param >
  
< param-name > org.apache.myfaces.AUTO_SCROLL </ param-name >
  
< param-value > true </ param-value >
  
< description >
   If true, a javascript function will be rendered that is able to restore the former vertical scroll on every request. Convenient feature if you have pages with long lists and you do not want the browser page to always jump to the top if you
   trigger a link or button action that stays on the same page. Default: 
&quot; false &quot;
  
</ description >
 
</ context-param >

  
< servlet-mapping >
  
< servlet-name > Faces Servlet </ servlet-name >
  
< url-pattern > *.jsf </ url-pattern >
 
</ servlet-mapping >
  

  
< listener >
  
< listener-class > org.apache.myfaces.webapp.StartupServletContextListener </ listener-class >
 
</ listener >

 
< listener >
  
< listener-class > org.springframework.web.context.ContextLoaderListener </ listener-class >
 
</ listener >

 
</ web-app >  

 

在JSF的配置文件(在web.xml中配置为faces-components-config.xml)中配置Spring解析器:

faces-components-config.xml:

<? xml version="1.0" encoding="UTF-8" ?>
<! DOCTYPE faces-config PUBLIC "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.0//EN"
                              "http://java.sun.com/dtd/web-facesconfig_1_0.dtd"
>
< faces-config >
 
< application >
    
< variable-resolver > org.springframework.web.jsf.DelegatingVariableResolver </ variable-resolver >
 
</ application >

</ faces-config >

之后就可以利用《JSF和Spring集成》中介绍的方法在类中访问faces-components-config.xml和applicationContext.xml中配置的类了

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值