1
votes

the project is developed in Spring 3, Spring web flow 2.3, Spring security 3 and Primefaces 3.2. When I use dispatcher servlet of JSF2 the view reload with AJAX perfectly and I can use tag h:link. But since I use dispatcher servlet from SWF I have started to have problem in two cases above.

For example, when I use h:link tag and its attribute outcome="listActivities, the result is href="WEB-INF/views/WEB-INF/views/listActivities.xhtml". I have could this problem using h:outputlink tag, because the result is href="listActivities" and I have configured SWF for to use UrlBasedViewResolver.

In the case using AJAX then the app not working and the message is serverError: class com.sun.faces.context.FacesFileNotFoundException /WEB-INF/views/WEB-INF/views/comunes/registro.xhtml Not Found in ExternalContext as a Resource. The same problem that using 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>

partial code view

    <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" />

The problem detected are: When I specific in URL /spring/.....

1- f:ajax tag dont call to the method in listener attribute but "reload" view and Second point occurs.

2- Repeat context path in URL /WEB-INF/views/WEB-INF/views/ this occurs when I use h:link tag or I change value in a h:selectOneMenu.

3- h:comammdbuton not working, listener attribute dont call to the method.

When I use in URL /faces/...... The above steps work fine.

Why occurs this behaviour?

Kind regards.

2
What king of tags are you using to define the scope of your beans? if you are using JSF tags try to change to spring mvc tags.IturPablo
Really, I am use JSF tags.Finally, I have had to advance in the project and unfortunately I have deprecated SWF, but I will remember for next time. Thank you very much.Rafael Ruiz Tabares

2 Answers

0
votes

The prefix in your faceletsViewResolver must be set to

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

and your *.xhtml files should go into the same folder as your flow definition

0
votes

I think, you have to modify your view at your flow. In Example :

<view-state id="idView" view="remove your prefix /WEB-INF/view/ so only the folder under that prefix">