Resources resolving for PrimeFaces with Spring WebFlow

Components, Ajax Framework, Utilities and More.
Post Reply
ejj
Posts: 30
Joined: 28 Jul 2010, 03:41

12 Aug 2010, 05:39

I am having a problem getting resources (javascript, etc) to resolve in a page with PrimeFaces component and SWF. The page displays, but is not including the PrimeFaces resources. Thoughts?

I am currently using PrimeFaces-2,1.RC1.jar with MyFaces 2.0.0 and Spring WebFlow 2.2.0M1.

I configured Spring Web Flow as per the blog entry http://blog.springsource.com/2010/08/05 ... -released/

I am looking to simply display the following page via SWF:

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
		
<html xmlns="http://www.w3.org/1999/xhtml"
         xmlns:h="http://java.sun.com/jsf/html"
         xmlns:f="http://java.sun.com/jsf/core"	
         xmlns:p="http://primefaces.prime.com.tr/ui">

<head>
 <title>test</title>
</head>
<body>
 <h:form>  
   	<p>This is a step in flow</p>
	<p:editor />
	<h:commandButton action="step1" value="step1" />
 </h:form>  
</body>
My web.xml is as follows:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.5" 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_2_5.xsd">

	<display-name>SpringFlowTestWeb</display-name>
	
	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>/WEB-INF/spring/applicationContext.xml</param-value>
	</context-param>
	
	<context-param>
		<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
		<param-value>server</param-value>
	</context-param>
	<context-param>
		<param-name>javax.faces.CONFIG_FILES</param-name>
		<param-value>/WEB-INF/faces-config.xml</param-value>
	</context-param>
	<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>

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

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

	<!-- Just here so the JSF implementation can initialize, *not* used at runtime -->
	<servlet>
		<servlet-name>Faces Servlet</servlet-name>
		<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
		<load-on-startup>1</load-on-startup>
	</servlet>
	
	<!-- Just here so the JSF implementation can initialize -->
	<servlet-mapping>
		<servlet-name>Faces Servlet</servlet-name>
		<url-pattern>
		*.faces</url-pattern>
	</servlet-mapping>
	<servlet-mapping>
		<servlet-name>Faces Servlet</servlet-name>
		<url-pattern>
		/faces/*</url-pattern>
	</servlet-mapping>
    <servlet>
      <servlet-name>Resource Servlet</servlet-name>
      <servlet-class>org.primefaces.resource.ResourceServlet</servlet-class>
    </servlet>
    <servlet-mapping>
      <servlet-name>Resource Servlet</servlet-name>
      <url-pattern>/primefaces_resource/*</url-pattern>
    </servlet-mapping>
    
    <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>/WEB-INF/spring/applicationContext-mvc.xml</param-value>
        </init-param>
        <load-on-startup>2</load-on-startup>
    </servlet>
    
    <servlet-mapping>
        <servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
        <url-pattern>/spring/*</url-pattern>
    </servlet-mapping>
	
</web-app>
My WebFlow configuration (applicationContext-mvc.xml):

Code: Select all

<?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:webflow="http://www.springframework.org/schema/webflow-config"
       xmlns:faces="http://www.springframework.org/schema/faces"
       xsi:schemaLocation="http://www.springframework.org/schema/beans 
           http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
           http://www.springframework.org/schema/webflow-config
           http://www.springframework.org/schema/webflow-config/spring-webflow-config-2.0.xsd
           http://www.springframework.org/schema/faces
           http://www.springframework.org/schema/faces/spring-faces-2.0.xsd">

	<!-- Maps JSF 2 resource requests to an instance of org.springframework.faces.webflow.FacesJsfResourceRequestHandler  -->
    <bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
      <property name="mappings" value="/javax.faces.resource/**=jsfResourceHandler"/>
    </bean>

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

    <bean id="jsfResourceHandler" class="org.springframework.faces.webflow.FacesJsfResourceRequestHandler"/>	

	<!-- Enables FlowHandler URL mapping -->
    <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>
    
    <bean class="org.springframework.webflow.mvc.servlet.FlowHandlerMapping">
      <property name="flowRegistry" ref="flowRegistry"/>
      <property name="order" value="0"/>
	  <property name="defaultHandler">
			<!-- If no flow match, map path to a view to render; e.g. the "/intro" path would map to the view named "intro" -->	
			<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/" />
		<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" />

	<!-- Dispatches requests mapped to org.springframework.web.HttpRequestHandler implementations -->	
	<bean class="org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter" />

    
	<!-- Executes flows: the central entry point into the Spring Web Flow system -->
	<webflow:flow-executor id="flowExecutor">
		<webflow:flow-execution-listeners>
			<webflow:listener ref="facesContextLifecycleListener"/>
		</webflow:flow-execution-listeners>
	</webflow:flow-executor>
	
	<!-- The registry of executable flow definitions -->
	<webflow:flow-registry id="flowRegistry" flow-builder-services="facesFlowBuilderServices">
	    <webflow:flow-location path="/WEB-INF/spring/test1.xml" />
	</webflow:flow-registry>
	
	<!-- Configures the Spring Web Flow JSF integration -->
	<faces:flow-builder-services id="facesFlowBuilderServices"/>

	<!-- Installs a listener that creates and releases the FacesContext for each request. -->
	<bean id="facesContextLifecycleListener" class="org.springframework.faces.webflow.FlowFacesContextLifecycleListener"/>

</beans>

User avatar
optimus.prime
Prime
Posts: 17371
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

12 Aug 2010, 10:40

PrimeFaces 2.2 and SWF 2.2 will introduce seamless integration.

What does a primefaces resource url return? You can try with an included resource url that has /primefaces_resource/ in it.

ejj
Posts: 30
Joined: 28 Jul 2010, 03:41

12 Aug 2010, 14:00

Here is more information about my problem.

When executing the simple flow (just trying to get a single page to display):

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
 <flow xmlns="http://www.springframework.org/schema/webflow"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://www.springframework.org/schema/webflow   http://www.springframework.org/schema/webflow/spring-webflow-2.0.xsd">

   <view-state id="step1" view="step1.xhtml">
   </view-state>

</flow>
The above mentioned page generates the html below. Note: the Javascript function call is generated to create the Prime Faces Editor (PrimeFaces.widget.Editor), however the script tags for the appropriate PrimeFaces resources are not created. Trying to determine why?

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
 <title>test</title>
</head>
<body><form id="j_id1721849521_66a156ab" name="j_id1721849521_66a156ab" method="post" action="/SpringFlowTestWeb/spring/test1?execution=e2s2" enctype="application/x-www-form-urlencoded">  
   	<p>This is a step in flow</p>
<div id="j_id1721849521_66a156ab:j_id1721849521_66a15685"><textarea id="j_id1721849521_66a156ab:j_id1721849521_66a15685:input" name="j_id1721849521_66a156ab:j_id1721849521_66a15685:input"></textarea></div><script type="text/javascript"><!--
widget_j_id1721849521_66a156ab_j_id1721849521_66a15685 = new PrimeFaces.widget.Editor('j_id1721849521_66a156ab:j_id1721849521_66a15685:input',{width:'500px',height:'300px',handleSubmit: true});
widget_j_id1721849521_66a156ab_j_id1721849521_66a15685.render();

//--></script><input id="j_id1721849521_66a156ab:j_id1721849521_66a156f2" name="j_id1721849521_66a156ab:j_id1721849521_66a156f2" type="submit" value="step1" /><input type="hidden" name="j_id1721849521_66a156ab_SUBMIT" value="1" /><input type="hidden" name="javax.faces.ViewState" id="javax.faces.ViewState" value="e2s2" /></form>  
</body>

</html>
Side note: I am looking forward to the integration of PF and SWF!! Keep up the good work.

User avatar
optimus.prime
Prime
Posts: 17371
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

13 Aug 2010, 10:35

You need to use h:head instead of head.

ejj
Posts: 30
Joined: 28 Jul 2010, 03:41

17 Aug 2010, 16:04

I changed to use h:head, script tags are now generated. Thanks! However I run into another problem. The HTML is now created as follows:

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
<html xmlns="http://www.w3.org/1999/xhtml"><head><link rel="stylesheet" media="screen" type="text/css" href="/SpringFlowTestWeb/spring/javax.faces.resource/jquery/plugins/ui/jquery.ui.autocomplete.css?ln=primefaces" /><script type="text/javascript" src="/SpringFlowTestWeb/spring/javax.faces.resource/jquery/jquery.js?ln=primefaces"><!--

//--></script><script type="text/javascript" src="/SpringFlowTestWeb/spring/javax.faces.resource/jquery/plugins/ui/jquery-ui.custom.js?ln=primefaces"><!--

//--></script><script type="text/javascript" src="/SpringFlowTestWeb/spring/javax.faces.resource/core/core.js?ln=primefaces"><!--

//--></script><script type="text/javascript" src="/SpringFlowTestWeb/spring/javax.faces.resource/autocomplete/autocomplete.js?ln=primefaces"><!--

//--></script>
<title>test</title></head><body><form id="j_id1685614094_64786e40" name="j_id1685614094_64786e40" method="post" action="/SpringFlowTestWeb/spring/test1?execution=e1s1" enctype="application/x-www-form-urlencoded">  
   	<p>This is step 13 (xhtml) of the flow</p>initset<label for="j_id1685614094_64786e40:acSimpleOut">Simple</label><input id="j_id1685614094_64786e40:acSimpleOut" name="j_id1685614094_64786e40:acSimpleOut" type="text" value="init 1 value" maxlength="10" />
    <br /><span id="j_id1685614094_64786e40:acSimple"><input id="j_id1685614094_64786e40:acSimple_input" name="j_id1685614094_64786e40:acSimple_input" type="text" value="" /></span><script type="text/javascript"><!--
jQuery(function(){widget_j_id1685614094_64786e40_acSimple = new PrimeFaces.widget.AutoComplete('j_id1685614094_64786e40:acSimple', {url:'/SpringFlowTestWeb/spring/test1?execution=e1s1',formId:'j_id1685614094_64786e40',pojo:false,maxResults:10});});
//--></script><input id="j_id1685614094_64786e40:j_id1685614094_64786ea7" name="j_id1685614094_64786e40:j_id1685614094_64786ea7" type="submit" value="step2" /><input type="hidden" name="j_id1685614094_64786e40_SUBMIT" value="1" /><input type="hidden" name="javax.faces.ViewState" id="javax.faces.ViewState" value="e1s1" /></form></body>
</html>
With the previously noted configuration. it appears the URLs are being resolved by the URLbasedViewResolver and
being prefixed and suffixed.

For example, In using Firebug, I see a GET perfomed for

http://localhost/SpringFlowTestWeb/spri ... primefaces

an exception is then generated by the web application, because the following file cannot be found:

/WEB-INF/javax.faces.resource/jquery/plugins/ui/jquery.ui.autocomplete.xhtml

Is there additional configuration that needs to be done to resolve the resources differently?


Here is my SWF configuration:

Code: Select all

<?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:webflow="http://www.springframework.org/schema/webflow-config"
       xmlns:faces="http://www.springframework.org/schema/faces"
       xsi:schemaLocation="http://www.springframework.org/schema/beans 
           http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
           http://www.springframework.org/schema/webflow-config
           http://www.springframework.org/schema/webflow-config/spring-webflow-config-2.0.xsd
           http://www.springframework.org/schema/faces
           http://www.springframework.org/schema/faces/spring-faces-2.0.xsd">

	<!-- Maps JSF 2 resource requests to an instance of org.springframework.faces.webflow.FacesJsfResourceRequestHandler  -->
    <bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
      <property name="mappings" value="/javax.faces.resource/**=jsfResourceHandler"/>
    </bean>

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

    <bean id="jsfResourceHandler" class="org.springframework.faces.webflow.FacesJsfResourceRequestHandler"/>	

	<!-- Enables FlowHandler URL mapping -->
    <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>
    
    <bean class="org.springframework.webflow.mvc.servlet.FlowHandlerMapping">
      <property name="flowRegistry" ref="flowRegistry"/>
      <property name="order" value="0"/>
	  <property name="defaultHandler">
	<!-- If no flow match, map path to a view to render; e.g. the "/intro" path would map to the view named "intro" -->	
		<bean class="org.springframework.web.servlet.mvc.UrlFilenameViewController" />
	  </property>
    </bean>

	<!-- Dispatches requests mapped to org.springframework.web.servlet.mvc.Controller implementations -->
	<bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter" />

	<!-- Dispatches requests mapped to org.springframework.web.HttpRequestHandler implementations -->	
	<bean class="org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter" />
    
	<!-- Executes flows: the central entry point into the Spring Web Flow system -->
	<webflow:flow-executor id="flowExecutor">
		<webflow:flow-execution-listeners>
			<webflow:listener ref="facesContextLifecycleListener"/>
		</webflow:flow-execution-listeners>
	</webflow:flow-executor>

	<!-- 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/" />
		<property name="suffix" value=".xhtml" />
	</bean>
	
	<!-- The registry of executable flow definitions -->
	<webflow:flow-registry id="flowRegistry" flow-builder-services="facesFlowBuilderServices">
	    <webflow:flow-location path="/WEB-INF/spring/test1.xml" />
	</webflow:flow-registry>
	
	<!-- Configures the Spring Web Flow JSF integration -->
	<faces:flow-builder-services id="facesFlowBuilderServices"/>

	<!-- Installs a listener that creates and releases the FacesContext for each request. -->
	<bean id="facesContextLifecycleListener" class="org.springframework.faces.webflow.FlowFacesContextLifecycleListener"/>

</beans>

Note: I am really looking forward to the SWF and PrimeFaces integration.

User avatar
optimus.prime
Prime
Posts: 17371
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

17 Aug 2010, 16:18

Can you try the Spring WebFlow forums as well, I'll forward this to SWF team.

ejj
Posts: 30
Joined: 28 Jul 2010, 03:41

17 Aug 2010, 19:02

Here is the solution:

Need to add the "order" property to the SimpleURLHandler so it will process resource requests before flow requests.

Code: Select all

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

Having updated to using primefaces-2.2.RC1-SNAPSHOT.jar, I now get the following error which is likely due to this .jar version being under development, but just wanted to let you know:

[8/17/10 11:30:16:559 CDT] 0000001c HtmlStyleshee W Resource referenced by resourceName /skins/sam/skin.css and libraryName primefaces not found in call to ResourceHandler.createResource. It will be silenty ignored.

Post Reply
  • Information
  • Who is online

    Users browsing this forum: Bing [Bot], Google [Bot] and 39 guests