2012-10-31 2 views
1

아래 프로젝트를 실행하려고하지만 Internet Explorer 9에서 문서 모드 인 IE9 표준에 "버그"가 표시됩니다. 그것은 단순히 CSS를로드하지 않습니다.봄/JSF를 사용하여보기가 CSS를로드하지 않습니다.

크롬, 파이어 폭스, IE 7 및 IE8, IE8 IE/IE7 표준에서 IE는 잘 작동합니다.

이 "버그"를 해결하기 위해 할 수있는 일이 무엇입니까 ???

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"> 
    <display-name>HibernateSpringJSFDispatcher</display-name> 
    <context-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value>/WEB-INF/application-context.xml</param-value> 
    </context-param> 
    <context-param> 
     <param-name>facelets.REFRESH_PERIOD</param-name> 
     <param-value>2</param-value> 
    </context-param> 
    <context-param> 
     <param-name>javax.faces.DEFAULT_SUFFIX</param-name> 
     <param-value>.xhtml</param-value> 
    </context-param> 
    <listener> 
     <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
    </listener> 
    <listener> 
     <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class> 
    </listener> 
    <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> 
    <servlet> 
     <servlet-name>DispatcherServlet</servlet-name> 
     <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
     <init-param> 
      <param-name>contextConfigLocation</param-name> 
      <param-value>/WEB-INF/application-context.xml</param-value> 
     </init-param> 
     <load-on-startup>1</load-on-startup> 
    </servlet> 
    <servlet-mapping> 
     <servlet-name>DispatcherServlet</servlet-name> 
     <url-pattern>/</url-pattern> 
    </servlet-mapping> 
</web-app> 

애플리케이션의 context.xml

<?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:context="http://www.springframework.org/schema/context" 
     xmlns:aop="http://www.springframework.org/schema/aop" 
     xmlns:tx="http://www.springframework.org/schema/tx" 
     xmlns:mvc="http://www.springframework.org/schema/mvc" 

     xsi:schemaLocation=" 
     http://www.springframework.org/schema/beans 
     http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
     http://www.springframework.org/schema/context 
     http://www.springframework.org/schema/context/spring-context-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 
     http://www.springframework.org/schema/mvc 
     http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"> 

    <context:component-scan base-package="br.gov.pr.maringa" /> 

    <import resource="classpath:persistence-context.xml"/> 

    <!-- map all requests to /resources/** to the container default servlet (ie, don't let Spring handle them) --> 

    <bean id="defaultServletHttpRequestHandler" class="org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler" /> 

    <bean id="simpleUrlHandlerMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> 
     <property name="urlMap"> 
     <map> 
      <entry key="/resources/**" value-ref="defaultServletHttpRequestHandler" /> 
      <entry key="/javax.faces.resource/**" value-ref="defaultServletHttpRequestHandler" /> 
     </map> 
     </property> 
    </bean> 

    <bean class="org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter" /> 

    <mvc:annotation-driven/> 
    <bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver"> 
     <property name="cache" value="false" /> 
     <property name="viewClass" value="org.springframework.faces.mvc.JsfView" /> 
     <property name="prefix" value="/WEB-INF/views/" /> 
     <property name="suffix" value=".xhtml" /> 
    </bean> 

    <bean id="entityManagerFactory" 
     class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> 
     <property name="loadTimeWeaver"> 
      <bean 
       class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver" /> 
     </property> 
     <property name="persistenceUnitName" value="persistence-unit" /> 
    </bean> 
</beans> 

면-config.xml에

<?xml version="1.0" encoding="UTF-8"?> 
<faces-config version="2.0" xmlns="http://java.sun.com/xml/ns/javaee" 
    xmlns:xi="http://www.w3.org/2001/XInclude" 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> 
     <resource-handler>br.gov.pr.maringa.hibernatespringjsfdispatcher.CustomResourceHandler</resource-handler> 
     <el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver> 
     <resource-bundle> 
      <base-name>MessageResources</base-name> 
      <var>messages</var> 
     </resource-bundle> 
    </application> 
</faces-config> 

CustomResourceHandler.java

package br.gov.pr.maringa.hibernatespringjsfdispatcher; 

import javax.faces.application.Resource; 
import javax.faces.application.ResourceHandler; 
import javax.faces.application.ResourceHandlerWrapper; 
import javax.faces.application.ResourceWrapper; 
import javax.faces.context.FacesContext; 

import com.sun.faces.util.Util; 

/** 
* Custom JSF ResourceHandler. 
* 
* This handler bridges between Spring MVC and JSF managed resources. The handler takes 
* care of the case when a JSF facelet is used as a view by a Spring MVC Controller and the 
* view uses components like h:outputScript and h:outputStylesheet by correctly pointing the 
* resource URLs generated to the JSF resource handler. 
* 
* The reason this custom handler wrapper is needed is because the JSF internal logic assumes 
* that the request URL for the current page/view is a JSF url. If it is a Spring MVC request, JSF 
* will create URLs that incorrectly includes the Spring controller context. 
* 
* This handler will strip out the Spring context for the URL and add the ".jsf" suffix, so the 
* resource request will be routed to the FacesServlet with a correct resource context (assuming the 
* faces servlet is mapped to the *.jsf pattern). 
* 
* 
*/ 
public class CustomResourceHandler extends ResourceHandlerWrapper { 

    private ResourceHandler wrapped; 

    public CustomResourceHandler(ResourceHandler wrapped) { 
     this.wrapped = wrapped; 
    } 
    @Override 
    public ResourceHandler getWrapped() { 
     return this.wrapped;  
    } 

    @Override 
    public Resource createResource(String resourceName, String libraryName) { 
     return new CustomResource(super.createResource(resourceName, libraryName)); 
    } 
    @Override 
    public Resource createResource(String resourceName, String libraryName, 
      String contentType) { 
     return new CustomResource(super.createResource(resourceName, libraryName, contentType)); 
    } 

    private static class CustomResource extends ResourceWrapper { 

     private Resource wrapped; 

     private CustomResource(Resource wrapped) { 
      this.wrapped = wrapped; 
     } 
     @Override 
     public Resource getWrapped() { 
      return this.wrapped; 
     } 
     @Override 
     public String getRequestPath() { 
      String path = super.getRequestPath(); 
      FacesContext context = FacesContext.getCurrentInstance(); 
      String facesServletMapping = Util.getFacesMapping(context); 
      // if prefix-mapped, this is a resource that is requested from a faces page 
      // rendered as a view to a Spring MVC controller. 
      // facesServletMapping will, in fact, be the Spring mapping 
      if (Util.isPrefixMapped(facesServletMapping)) { 
       // remove the Spring mapping 
       path = path.replaceFirst("(" + facesServletMapping + ")/", "/"); 
       // append .jsf to route this URL to the FacesServlet 
       path = path.replace(wrapped.getResourceName(), wrapped.getResourceName() + ".jsf"); 
      } 
      return path; 
     } 

    } 
} 
,536,913,632 10

HelloWorldController.java

package br.gov.pr.maringa.hibernatespringjsfdispatcher.controller; 

import org.springframework.beans.factory.annotation.Autowired; 
import org.springframework.stereotype.Controller; 
import org.springframework.web.bind.annotation.RequestMapping; 
import org.springframework.web.bind.annotation.RequestMethod; 
import org.springframework.web.bind.annotation.RequestParam; 

import br.gov.pr.maringa.exception.InvalidEntityException; 
import br.gov.pr.maringa.hibernatespringjsfdispatcher.model.HelloWorld; 
import br.gov.pr.maringa.hibernatespringjsfdispatcher.model.Usuario; 
import br.gov.pr.maringa.hibernatespringjsfdispatcher.model.UsuarioHome; 

@Controller 
public class HelloWorldController { 

    @Autowired 
    private HelloWorld helloWorld; 
    @Autowired 
    private UsuarioHome uh; 

    @RequestMapping(value="/helloWorld", method=RequestMethod.GET) 
    public void helloWorld() { 
     helloWorld.setMessage("Hello World from Spring MVC to JSF"); 

     Usuario u = new Usuario(); 

     u.setUsuario("claudio"); 
     u.setSenha("1234"); 

     try { 
      uh.save(u); 
     } catch (InvalidEntityException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 
    } 
    @RequestMapping(value="/helloWorld", method=RequestMethod.POST) 
    public void helloWorldPost(@RequestParam String msg) { 
     helloWorld.setMessage(msg); 
    } 
} 

helloWorld.xhtml

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" 
    xmlns:p="http://primefaces.org/ui" 
    xmlns:h="http://java.sun.com/jsf/html" 
    xmlns:ui="http://java.sun.com/jsf/facelets"> 
    <h:head> 
     <title>Hello World</title> 
    </h:head> 
    <h:body> 
     <p>${helloWorld.message}</p> 
     <p:panel header="qualquercoisa">abc</p:panel> 
     <p>Say something: </p> 
     <form method="post"> 
      <input name="msg" type="text"></input> 
      <input type="submit" ></input> 
     </form> 
     <p>This image is linked as a JSF resource</p> 
     <h:graphicImage name="images/jsf.jpg" /> 
     <p>This image is directly linked</p> 
     <img src="resources/images/spring.png"></img> 
    </h:body> 
</html> 

참고 : http://papweb.wordpress.com/2011/07/29/spring-mvc-3-jsf-2-with-maven-2-and-tomcat/

답변

1

IE9 표준 모드는 Content-Type: text/css CSS 리소스를 사용할 수 있습니다. 다른 콘텐츠 형식이 반환되면 IE9는 전체 CSS 리소스를 모두 무시합니다.

사용자 지정 리소스 처리기에서 적절한 콘텐츠 형식 헤더를 설정해야합니다. 나는 Spring이 여기서 어떤 역할을하는지, 그리고이 커스텀 리소스 핸들러가이 컨스트럭션에서 얼마나 정확한지는 모르지만 기본적으로 컨텐트 타입은 파일 확장자를 기반으로 설정되어있다. 적어도 CustomResourceResource#getContentType() 방법이 text/css을 반환하는지 확인해야합니다.

관련 문제