Announcement Announcement Module
Collapse
No announcement yet.
Spring JSF integration - what is wrong? please help me out Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring JSF integration - what is wrong? please help me out

    Hi,

    I am new to the Spring Framework.
    Currently I try to understand how to configure Spring with JSF.
    For now, everything works except executing action to the backingbeans.
    Pressing on any of the submit buttons takes me into a

    "The requested resource (/swd/WEB-INF/jsp/menue.jsf) is not available."

    Error. I think this might be an servlet-mapping mistake, but I just don't know how to work it out.
    Maybe I didn't understand how to use jsf and spring the right way, but I thought this would be ok.
    Pleas help me out

    Jan

    The project is called "swd"
    I am using spring 1.2.3.

    Workflow:
    Calling menue.htm
    --> mapping to MenueController.java --> fills Beans for View returns
    --> ModelAndView directs to /WEB-INF/jsp/menue.jsp everything is ok -
    --> jsf renders the h:datatabel filled with list of beans.
    --> click on save button --> error as mentioned before
    (the save method is a public function in the backingbean, I think I don't have to post this).

    System-description:

    Web.xml (partial):
    :::::
    Code:
    <!-- entry for faces context -->
        <servlet-mapping>
            <servlet-name>FacesServlet</servlet-name>
            <url-pattern>*.jsf</url-pattern>
        </servlet-mapping>     
    
    <!-- entry for spring servlet &#58;&#58; swd-servlet.xml -->      
        <servlet-mapping>
            <servlet-name>swd</servlet-name>
            <url-pattern>*.htm</url-pattern>
        </servlet-mapping>
    :::::

    Faces-config.xml : (navigation-rules doesnít seem to have any effect concerning this problem)
    ::::
    Code:
    	<faces-config>
    	 <application>
    		<variable-resolver>org.springframework.web.jsf.DelegatingVariableResolver</variable-resolver>		
    	 </application>
    	</faces-config>
    ::::

    swd-servlet.xml (partial):
    :::::
    Code:
    	<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
            <property name="viewClass"><value>org.springframework.web.servlet.view.JstlView</value></property>
            <property name="prefix"><value>/WEB-INF/jsp/</value></property>
            <property name="suffix"><value>.jsf</value></property>        
        </bean>
    :::::

    applicationContext.xml (partial):
    :::::
    Code:
    <bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
            <property name="mappings">
                <props>                
                    <prop key="menue.htm">menueController</prop>
                </props>
            </property>
        </bean>
    :::::

    MenueController.java (partial) [implements Controller]:
    ::::
    Code:
    public ModelAndView handleRequest&#40;HttpServletRequest req, HttpServletResponse resp&#41; throws ServletException, IOException &#123;
        	
        	
        	...
    	now = ...
    	MMEBList = ....
        	
    
        	Map myModel = new HashMap&#40;&#41;;
        	myModel.put&#40;"time", now&#41;;
        	myModel.put&#40;"menuelist", MMEBList&#41;;
        	    
        	
          return new ModelAndView&#40;"menue","model",myModel&#41;;
        &#125;
    ::::

  • #2
    "The requested resource (/swd/WEB-INF/jsp/menue.jsf) is not available." indicates that you are requesting the jsf from the wrong place

    Change your view definitions so they load from "/WEB-INF/jsp.menue.jsf".

    HTH.

    Comment


    • #3
      Thanks for your reply, but in which way am I able to change this?

      The requested resource is a request made by the form. I didnít know it is even possible to modify that.
      I mean, the request is done by menue.jsp (menue.jsf).
      And itself requests /swd/WEB-INF/jsp/menue.jsf .
      (I think the path is right, except that the physical file is menue.jsp, but this shouldnít make a difference, or?)
      Shouldnít the servlet mapping *.jsf take this request.

      I have already used JSF in a few Projects, but I have never had such problems.

      Maybe I am totally stupid, but would you please be so kind and help me again.

      Jan

      Comment


      • #4
        AFAIK WEB-INF has to be the top level folder in your war, so "/swd/WEB-INF/" will not exist, only "/WEB-INF/".

        I do not know anything about JSF, but I presume you have your views setup in spring?

        The servlet mapping maps onto your controllers, your controller returns a view name, the view name is converted into an actual view (jsp, jsf, velocity etc.) Can you post your web.xml, jsp and servlet.xml.

        Comment


        • #5
          Ok, letís try again

          First of all my folder setup:
          swd (project name)
          • - JavaSource (source files, packages)
            - WebContent (alias for war, index.jsp)
            - - META-INF
            - - WEB-INF (web.xml, swd-servlet.xml, faces-config.xml, applicationContext.xml)
            - - - classes
            - - - jsp (menue.jsp)
            - - - lib (jars)
            - - - tld (spring.tld)

          Web.xml (complete)
          Code:
          <?xml version="1.0" encoding="UTF-8"?>
          <web-app id="WebApp_ID" version="2.4" xmlns="http&#58;//java.sun.com/xml/ns/j2ee" xmlns&#58;xsi="http&#58;//www.w3.org/2001/XMLSchema-instance" xsi&#58;schemaLocation="http&#58;//java.sun.com/xml/ns/j2ee http&#58;//java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
          	<display-name>swd</display-name>
          	 
              <listener>
              	<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
              </listener>
              
              <servlet>
          	    <servlet-name>swd</servlet-name>
          	    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
          	    <load-on-startup>1</load-on-startup>
            	</servlet>
          	
              <servlet>
                  <servlet-name>FacesServlet</servlet-name>
                  <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
                  <load-on-startup>1</load-on-startup>
              </servlet>
          	
          	 
          	 <servlet>
          	  <servlet-name>SpringContextServlet</servlet-name>
          	  <servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class>	  
          	  <load-on-startup>1</load-on-startup>
              </servlet>
             
             
              <servlet-mapping>
                  <servlet-name>FacesServlet</servlet-name>
                  <url-pattern>*.jsf</url-pattern>
              </servlet-mapping> 
              
              
              <servlet-mapping>
                  <servlet-name>swd</servlet-name>
                  <url-pattern>*.htm</url-pattern>
              </servlet-mapping>   
              
              <welcome-file-list>
              	<welcome-file>index.jsp</welcome-file>
              </welcome-file-list>
          	
          	<taglib>
          	    <taglib-uri>/spring</taglib-uri>
          	    <taglib-location>/WEB-INF/tld/spring.tld</taglib-location>
            	</taglib>
          	
          </web-app>
          The menue.jsp (complete)
          (used to show the entries and to perform a simple action on a bean, by use of jsf. The View via h:datatable works fine, but a click on the button fails) Ė as you can see this is slightly modified from the step by step tutorial.
          Code:
          <%@ include file="/WEB-INF/jsp/include.jsp" %>
          
          <%@ taglib uri="http&#58;//java.sun.com/jsf/html" prefix="h"%>
          <%@ taglib uri="http&#58;//java.sun.com/jsf/core" prefix="f"%>
          
          <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
          <f&#58;view>
          <f&#58;loadBundle basename="jwint001.resources.messages.messages" var="msg"/>
          <f&#58;verbatim>
          <html>
          <head></f&#58;verbatim>
          <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
              pageEncoding="ISO-8859-1"%>
          <f&#58;verbatim><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
          <title>Insert title here</title>
          </head>
          <body></f&#58;verbatim>
          <h1><fmt&#58;message key="heading"/></h1>
          <p><fmt&#58;message key="greeting"/> <c&#58;out value="$&#123;model.zeit&#125;"/></p>
          
          <f&#58;verbatim>from Model and view</f&#58;verbatim>
          <h&#58;form id="form">
          <h&#58;dataTable id="menue" 
          	styleClass="listtable" 								
          	value="#&#123;model.menue.MMEBeans&#125;"
          	headerClass="listheader"
              rowClasses="listrow1,listrow2"
          	var="entry" 
          	rows="10"	
              cellpadding="5" cellspacing="0">
          	<h&#58;column>
          		<f&#58;facet name="header">			
                  <h&#58;outputText value="Name"/>                      								
          		</f&#58;facet>									
          			<h&#58;outputText id="Name" value="#&#123;entry.name&#125;"/>
          	</h&#58;column>
          	<h&#58;column>
          		<f&#58;facet name="header">
          				<h&#58;outputText value="Link"/>
          		</f&#58;facet>
          			<h&#58;inputText id="Link" value="#&#123;entry.link&#125;"/>
          	</h&#58;column>
          	<h&#58;column>
          		<h&#58;commandButton value="#&#123;msg.user_button_save&#125;" alt="#&#123;msg.user_button_save&#125;" actionListener="#&#123;entry.save&#125;"/>
          	</h&#58;column>
          </h&#58;dataTable>
          <h&#58;commandButton value="#&#123;msg.user_button_save&#125;" alt="#&#123;msg.user_button_save&#125;" actionListener="#&#123;model.menue.show&#125;"/>
          </h&#58;form>
          <br/>
          <f&#58;verbatim>
          </body>
          </html></f&#58;verbatim>
          </f&#58;view>
          swd-servlet.xml (complete)
          Code:
          <?xml version="1.0" encoding="UTF-8"?>
          <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http&#58;//www.springframework.org/dtd/spring-beans.dtd">
          
          <beans>	    
          	<!-- ViewResolver nutzt JSP Pages als View-Elemente  --> 
              <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
                  <property name="viewClass"><value>org.springframework.web.servlet.view.JstlView</value></property>
                  <property name="prefix"><value>WEB-INF/jsp/</value></property>
                  <property name="suffix"><value>.jsf</value></property>        
              </bean>    
               
              <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
                  <property name="basename"><value>jwint001.resources.messages.messages</value></property>
              </bean> 	 
          
          </beans>
          applicationContext.xml (for urlMapping)
          Code:
          <?xml version="1.0" encoding="UTF-8"?>
          <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http&#58;//www.springframework.org/dtd/spring-beans.dtd">
          
          <beans>
          	<bean id="menueController" class="jwint001.controller.MenueController" singleton="true">
          		<property name="MMEBList"> 
              		<ref bean="MainMenueEntryBeanList"/>
              	</property>
              </bean>
              
              <bean id="MainMenueEntryBeanList" class="jwint001.model.beans.MainMenueEntryBeanList" singleton="true" />
              <bean id="MainMenueEntryBean" class="jwint001.model.beans.MainMenueEntryBean" singleton="false" />  
          	
          	
          	<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
                  <property name="mappings">
                      <props>                
                          <prop key="menue.htm">menueController</prop>
                      </props>
                  </property>
              </bean>	          	
             
          </beans>

          Comment


          • #6
            I have a feeling that the problem will be in faces-config.xml, can you post that please

            Comment


            • #7
              The faces-config.xml doesnít handle the beans, I would prefer just to use spring-beans. And even if I add faces managed beans, the problem still exists.
              Also navigation-rules didnít seem to change anything. So I didnít mention them in the faces-config for now.
              Therefore the faces-config is very short (no beans and no navigation-rules inside).

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

              :wink:

              Comment


              • #8
                I am at a loss then, sorry Can you do a search on the file system for "/swd/WEB-INF/jsp/menue.jsf" and see what it throws up.

                Comment


                • #9
                  Nevertheless thank you for your help. If I find what's wrong, I will post it, maybe it is interesting for others as well.

                  :wink:

                  Comment


                  • #10
                    So, finally I got it. Of cause it was something simple, as every time.
                    The example, which has been the base of my testapplication, stored the jsps in the jsp folder under WEB-INF. This hadnít been a problem, cause every request was redirected by a servlet (or something in that way). I didnít remember that a direct request to a folder in WEB-INF isnít allowed :wink: . So my testapplication did a forbidden request, cause there is no servlet mapping this action, it is just a simple request to the same source.
                    So, moving the jsp folder out of WEB-INF had been the solution.

                    :P

                    Comment

                    Working...
                    X