1

该项目是在 Spring 3、Spring web flow 2.3、Spring security 3 和 Primefaces 3.2 中开发的。当我使用 JSF2 的调度程序 servlet 时,视图会完美地使用 AJAX 重新加载,我可以使用标签 h:link。但由于我使用 SWF 的调度程序 servlet,我在上述两种情况下开始遇到问题。

例如,当我使用h:link标记及其属性output="listActivities,结果是href="WEB-INF/views/WEB-INF/views/listActivities.xhtml"。我可以使用h:outputlink解决这个问题标记,因为结果是 href="listActivities" 并且我已将 SWF 配置为使用 UrlBasedViewResolver。

在使用 AJAX 的情况下,应用程序无法正常工作并且消息是 serverError: class com.sun.faces.context.FacesFileNotFoundException /WEB-INF/views/WEB-INF /views/comunes/registro.xhtml Not Found in ExternalContext 作为资源。与使用 h:link 相同的问题。

web.xml

 <!-- Extensión por defecto para el uso de Facelets -->

<context-param>
  <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
  <param-value>.xhtml</param-value>
</context-param>

<context-param>
  <param-name>javax.faces.PROJECT_STAGE</param-name>
  <param-value>Development</param-value>
</context-param>


<!-- Archivo de configuración de Spring -->

<context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>

<filter>
    <filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
    <filter-name>springSecurityFilterChain</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

  <filter>
   <filter-name>charEncodingFilter</filter-name>
   <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
  <init-param>
    <param-name>encoding</param-name>
    <param-value>UTF-8</param-value>
  </init-param>
  <init-param>
    <param-name>forceEncoding</param-name>
    <param-value>true</param-value>
  </init-param>
  </filter>
  <filter-mapping>
    <filter-name>charEncodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>

  <!-- Carga el spring web application context -->

  <listener>
    <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
  </listener>

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

  <listener>
    <listener-class>
      org.springframework.web.context.request.RequestContextListener
    </listener-class>
  </listener>

    <!-- Servlet para los recursos de la aplicación -->

   <servlet>
 <servlet-name>Resources Servlet</servlet-name>
 <servlet-class>org.springframework.js.resource.ResourceServlet</servlet-class>
 <load-on-startup>0</load-on-startup>
   </servlet>

   <servlet-mapping>
 <servlet-name>Resources Servlet</servlet-name>
 <url-pattern>/resources/*</url-pattern>
   </servlet-mapping>

   <!-- FronController de la aplicación, maneja todas las request -->

  <servlet>
<servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
    <param-name>contextConfigLocation</param-name>
    <param-value></param-value>
</init-param>
<load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
<servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
<url-pattern>/spring/*</url-pattern>
  </servlet-mapping>

<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>/faces/*</url-pattern>
</servlet-mapping>
</web-app>

webflow-config.xml

<!-- Configuración Spring webflow para JSF 2 -->


<bean id="flowController"
           class="org.springframework.webflow.mvc.servlet.FlowController">  
      <property name="flowExecutor" ref="flowExecutor"/>  
    </bean>  


<!-- Configure Web Flow to be able to recognize JSF 2 Ajax requests -->

<bean class="org.springframework.webflow.mvc.servlet.FlowHandlerAdapter">
    <property name="flowExecutor" ref="flowExecutor" />
    <property name="ajaxHandler">
        <bean class="org.springframework.faces.webflow.JsfAjaxHandler"/>
    </property>
</bean>

<!-- Executes flows: the central entry point into the Spring Web Flow system -->

<webflow:flow-executor id="flowExecutor">
    <webflow:flow-execution-listeners>
        <webflow:listener ref="facesContextListener"/>
        <webflow:listener ref="securityFlowExecutionListener" />
    </webflow:flow-execution-listeners>
    <webflow:flow-execution-attributes>
        <webflow:redirect-in-same-state value="false"/>
    </webflow:flow-execution-attributes>
</webflow:flow-executor>

<!-- The registry of executable flow definitions -->

<webflow:flow-registry id="flowRegistry" 
          flow-builder-services="facesFlowBuilderServices" base-path="/WEB-INF/flows">
    <webflow:flow-location-pattern value="/**/*-flow.xml" />
</webflow:flow-registry>

<!-- Configures the Spring Web Flow JSF integration -->

<faces:flow-builder-services id="facesFlowBuilderServices" development="true" />

<!-- Installs a listener that creates and releases the FacesContext for 
            each request. -->

<bean id="facesContextListener"
         class="org.springframework.faces.webflow.FlowFacesContextLifecycleListener"/>

<!-- Installs a listener to apply Spring Security authorities -->

<bean id="securityFlowExecutionListener"
         class="org.springframework.webflow.security.SecurityFlowExecutionListener" />


    <!-- configuración MVC para JSF 2 -->

<faces:resources/>

<!-- Dispatches requests mapped to flows to FlowHandler implementations -->

<bean class="org.springframework.faces.webflow.JsfFlowHandlerAdapter">
    <property name="flowExecutor" ref="flowExecutor" />
</bean>

<!-- Maps request paths to flows in the flowRegistry -->

<bean class="org.springframework.webflow.mvc.servlet.FlowHandlerMapping">
    <property name="order" value="1"/>
    <property name="flowRegistry" ref="flowRegistry" />
    <!-- If no flow match, map path to a view to render; e.g. the "/intro" path 
             would map to the view named "intro"    -->
    <property name="defaultHandler">
<bean  class="org.springframework.web.servlet.mvc.UrlFilenameViewController" />
    </property>
</bean>

<!-- Maps logical view names to Facelet templates in /WEB-INF (e.g. 'search' to 
     '/WEB-INF/search.xhtml' -->

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

<!-- Dispatches requests mapped to org.springframework.web.servlet.mvc.Controller
         implementations -->

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

部分代码视图

    <ui:define name="content">
    <div class="registroUsuario">
    <h:form id="registroForm">
        <h:panelGrid columns="3">

    <h:outputLabel for="distrito" value="Distrito" styleClass="labelInput" />

    <h:selectOneMenu id="distrito" required="true" requiredMessage="Debe seleccionar un
       distrito" value="#{registro.idDistrito}" title="Seleccione su distrito">

     <f:selectItem itemLabel="Seleccione distrito" itemValue="0"
              noSelectionOption="true"></f:selectItem>
    <f:selectItems var="distrito" value="#{registro.distritos}" itemLabel="#
          {distrito.nombre}" itemValue="#{distrito.idDistrito}">
    </f:selectItems>

    <f:ajax update="barrio calle messageDistrito" render="barrio calle messageDistrito" 
          listener="#{registro.updateBarrio}" event="blur" />

    <f:validateBean for="idDistrito" />
    </h:selectOneMenu>

      <h:message id="messageDistrito" for="distrito" styleClass="messageError" />           

    <h:outputLabel for="barrio" value="Barrio" styleClass="labelInput" />
    <h:selectOneMenu id="barrio" effect="fade" required="true" requiredMessage="Debe
     seleccionar un barrio" value="#{registro.idBarrio}" title="Seleccione su barrio ">

  <f:selectItem itemLabel="Seleccione barrio" itemValue="0" noSelectionOption="true" />     

<f:selectItems var="barrio" value="#{registro.barrios}" itemLabel="#{barrio.nombre}"
               itemValue="#{barrio.idBarrio}">
</f:selectItems>

<f:ajax render="calle messageBarrio" listener="#{registro.updateCalle}" 
         event="valueChange" />
<f:validateBean for="idBarrio" />
</h:selectOneMenu>
<h:message id="messageBarrio" for="barrio" styleClass="messageError" />

检测到的问题是:当我具体在 URL /spring/.....

1- f:ajax 标签不调用侦听器属性中的方法,但“重新加载”视图和第二点发生。

2- 在 URL /WEB-INF/views/WEB-INF/views/中重复上下文路径,当我使用 h:link 标记或更改 ah:selectOneMenu 中的值时会发生这种情况。

3- h:comammdbuton 不起作用,侦听器属性不调用该方法。

当我在 URL /faces/......中使用时,上述步骤工作正常。

为什么会出现这种行为?

亲切的问候。

4

2 回答 2

0

我认为,您必须在流程中修改您的视图。在示例中:

<view-state id="idView" view="remove your prefix /WEB-INF/view/ so only the folder under that prefix">
于 2014-07-18T10:07:07.587 回答
0

faceletsViewResolver 中的前缀必须设置为

<property name="prefix" value="/WEB-INF/" />

并且您的 *.xhtml 文件应该与您的流程定义进入同一文件夹

于 2013-04-01T17:23:35.223 回答