facebook

JSF and Spring

💡
Our Forums Have Moved

For help with installation, bugs reports or feature requests, please head over to our new forums.
Genuitec Community on GitHub

  1. MyEclipse IDE
  2.  > 
  3. Off Topic
Viewing 15 posts - 1 through 15 (of 15 total)
  • Author
    Posts
  • #246021 Reply

    alombard
    Member

    – System Setup ——————————-
    Operating System and version: XP pro SP1
    Eclipse version: 3.1.1
    Eclipse build id: M20050929-0840
    Fresh Eclipse install (y/n): y
    If not, was it upgraded to its current version using the update manager?
    Other installed external plugins: yes
    Number of plugins in the <eclipse>/plugins directory that begin with org.eclipse.pde.*: 8
    MyEclipse version: 4.1.0
    Eclipse JDK version: 1.5.0_06
    Application Server JDK version: Tomcat 5.5.12
    Are there any exceptions in the Eclipse log file? n
    – Message Body ——————————-

    Hello,

    I am new to MyEclipse (4.1.0 GA) and I want to develop a web application with JSF and Spring.
    I have begun with JSF LoginDemo from the help.

    Then, I added the Spring Capabilities to the project.
    I created an empty UserService interface, and an empty UserServiceImpl class.
    In the (existing) UserBean.java, I added a property of type UserService and generated the getter and setter.

    In the faces-config.xml, I added the variable-resolver:

    <application>
        <variable-resolver>org.springframework.web.jsf.DelegatingVariableResolver</variable-resolver>
        <locale-config>
            <default-locale>en</default-locale>
            <supported-locale>en</supported-locale>
            <supported-locale>fr</supported-locale>
        </locale-config>
    </application>

    and the managed property of the managed bean UserBean:

        <managed-property>
            <property-name>userService</property-name>
            <value>#{userService}</value>
        </managed-property>

    And in the applicationContext.xml, I added the bean userService :

    <bean id="userService" class="com.jsfdemo.business.bean.UserServiceImpl" abstract="false" singleton="true" lazy-init="default" autowire="default" dependency-check="default"></bean>

    Then, when I deploy and go to the Page, I get the following:

    javax.servlet.ServletException: Expression: '#{UserBean.userName}'
        javax.faces.webapp.FacesServlet.service(FacesServlet.java:125)

    Interesting is that when I remove #{userService} of the value of the managed property, it works fine (except that the userService property of UserBean is not initialized).

    I tried with the 3 JSF implementations (Sun RI 1.1.01, MyFaces 1.0.9 and 1.1.1?) with the same results.

    I have looked around I saw that there were compatibility issues with Spring’s DelegatingVariableResolver and JSF.

    So, I would like to know if anyone did something with JSF and Spring, with or without MyEclipse, and how.

    Many thanks for your help

    *** Date: Fri Feb 03 17:13:08 CET 2006

    *** System properties:
    OS=WindowsXP
    OS version=5.1
    Java version=1.5.0_06

    *** MyEclipse details:
    MyEclipse Enterprise Workbench

    Version: 4.1.0 GA
    Build id: 20060122-4.1-GA

    *** Eclipse details:
    Eclipse SDK

    Version: 3.1.1
    Build id: M20050929-0840

    Eclipse Platform

    Version: 3.1.1
    Build id: M20050929-0840

    Eclipse Java Development Tools

    Version: 3.1.1
    Build id: M20050929-0840

    Eclipse Plug-in Development Environment

    Version: 3.1.1
    Build id: M20050929-0840

    Eclipse Project SDK

    Version: 3.1.1
    Build id: M20050929-0840

    Eclipse Graphical Editing Framework

    Version: 3.1
    Build id: 200509301327

    Eclipse RCP

    Version: 3.1.1
    Build id: M20050929-0840

    Eclipse startup command=-os
    win32
    -ws
    win32
    -arch
    x86
    -launcher
    D:\Program Files\eclipse\eclipse.exe
    -name
    Eclipse
    -showsplash
    600
    -exitdata
    89c_58
    -vm
    D:\jdk1.5.0_06\jre\bin\javaw.exe

    #246035

    Riyad Kalla
    Member

    Moving to OT > Soft Dev, this is a JSF/Spring issue.

    Off the top of my head I really have no idea, I haven’t played with the var resolving and JSF.

    #253839

    Hi,

    I solved the problem some times ago and I am not sure of the solution.
    But I think it had something to do with the web.xml.

    From what I have, I would say that it is necessary to load a spring context servlet like this:

    
        <servlet>
            <servlet-name>SpringContextServlet</servlet-name>
            <servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class>
            <load-on-startup>1</load-on-startup>
        </servlet>
    

    I hope this helps.

    #257107

    bansi
    Member

    Could you pl let me know how to resolve the issue at it shows the following error in IDE
    “org.springframework.web.jsf.DelegatingVariableResolver is not a subtype of javax.faces.el.VariableResolver”

    #257118

    Riyad Kalla
    Member

    bansi,
    This might be an error in the IDE, can you post all the system information from your MyEclipse > Installation Summary > Installation Details screen for us, also can you paste the snippet of your faces-config file that is causing the problem and enough information so we can reproduce this problem locally.

    #257155

    bansi
    Member

    Thanks for your response. Here is the info
    *** System properties:
    OS=WindowsXP
    OS version=5.1
    Java version=1.4.2_04

    *** MyEclipse details:
    MyEclipse Enterprise Workbench

    Version: 4.1.0 GA
    Build id: 20060122-4.1-GA

    *** Eclipse details:
    Eclipse SDK

    Version: 3.1.1
    Build id: M20050929-0840

    Eclipse Platform

    Version: 3.1.1
    Build id: M20050929-0840

    Eclipse RCP

    Version: 3.1.1
    Build id: M20050929-0840

    Eclipse Java Development Tools

    Version: 3.1.1
    Build id: M20050929-0840

    Eclipse Plug-in Development Environment

    Version: 3.1.1
    Build id: M20050929-0840

    Eclipse Project SDK

    Version: 3.1.1
    Build id: M20050929-0840

    Eclipse startup command=-os
    win32
    -ws
    win32
    -arch
    x86
    -launcher
    C:\eclipse\eclipse\eclipse.exe
    -name
    Eclipse
    -showsplash
    600
    -exitdata
    b44_60
    -vm
    C:\j2sdk1.4.2_04\bin\javaw.exe

    Here is faces-config file which shows “Red” crossmark in the IDE at <variable-resolver> tag stating that “org.springframework.web.jsf.DelegatingVariableResolver is not a subtype of javax.faces.el.VariableResolver”

    <?xml version=”1.0″ encoding=”UTF-8″?>
    <!DOCTYPE faces-config PUBLIC “-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN” “http://java.sun.com/dtd/web-facesconfig_1_1.dtd”&gt;

    <faces-config>
    <!– Allows you to inject Spring beans into JSF managed beans… –>
    <application>
    <variable-resolver>org.springframework.web.jsf.DelegatingVariableResolver</variable-resolver>
    </application>

    <managed-bean>
    <managed-bean-name>showRooms</managed-bean-name>
    <managed-bean-class>hotelReservations.ShowRooms</managed-bean-class>
    <managed-bean-scope>request</managed-bean-scope>
    <managed-property>
    <property-name>manager</property-name>
    <value>#{manager}</value>
    </managed-property>
    </managed-bean>

    </faces-config>

    #257181

    Riyad Kalla
    Member

    Thank you for the example, I believe this bug was fixed in one of our later releases. I just tried your example in MyEclipse 5.0.1 (installed on Eclipse 3.2) and there was no error marker.

    You can try doing a simultaneous install of Eclipse 3.2 SDK and MyEclipse 5.0.1 to new directories and try the same example on your end. I tried on two setups here an they worked fine.

    #257616

    Jeremy Stein
    Member

    Going back to the problem in the original post, the issue was that Spring was never loaded. The second poster (avintis) suggested using ContextLoaderServlet, but it would be better to use ContextLoaderListener as listeners are loaded before servlets. So, this should be added to web.xml:

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

    By default, MyEclipse 5 (I’m not sure about 4) puts applicationContext.xml in src, which means it gets copied to WEB-INF/classes. Spring expects it to be in WEB-INF, so you have to also add this to web.xml to tell Spring where to find the file:

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

    In any case, it’s also a good idea to configure log4j, so that Spring can tell you when it has a problem (such as being unable to find its config file). Drop log4j.properties in src:

    log4j.rootCategory=INFO, stdout
    
    log4j.appender.stdout=org.apache.log4j.ConsoleAppender
    log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
    log4j.appender.stdout.layout.ConversionPattern=[@APPNAME@] %p [%t] %c{1}.%M(%L) | %m%n
    
    log4j.logger.org.springframework=WARN
    #258002

    bansi
    Member

    Hi Riyad
    As suggested by you i tried on MyEclipse 3.2 and MyEclipse5.0 unfortunately the problem still persist.
    Also as suggested by JeremyStein i have the foolowing files
    <application>
    <variable-resolver>org.springframework.web.jsf.DelegatingVariableResolver</variable-resolver>
    </application>

    <managed-bean>
    <managed-bean-name>showRooms</managed-bean-name>
    <managed-bean-class>hotelReservations.ShowRooms</managed-bean-class>
    <managed-bean-scope>application</managed-bean-scope>
    <managed-property>
    <property-name>manager</property-name>
    <value>#{manager}</value>
    </managed-property>
    </managed-bean>

    <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/classes/applicationContext.xml</param-value>
    </context-param>
    <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>
    <session-config>
    <session-timeout>30</session-timeout>
    </session-config>
    <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>

    <bean id=”roomDAO” class=”hotelReservations.dao.RoomDaoHibernate”>
    <property name=”hibernateTemplate”>
    <ref bean=”hibernateTemplate”/>
    </property>
    </bean>

    <bean id=”hibernateTemplate”
    class=”org.springframework.orm.hibernate3.HibernateTemplate”>
    <property name=”sessionFactory”>
    <ref bean=”sessionFactory”/>
    </property>
    </bean>

    <!–Manager for Hotel rooms application.–>
    <bean id=”hotelManager” class=”hotelReservations.HotelManager”>
    <property name=”roomDAO”>
    <ref local=”roomDAO”/>
    </property>
    </bean>

    <!–Wraps manager in order to support transactions.–>
    <bean id=”manager” class=”org.springframework.transaction.interceptor.TransactionProxyFactoryBean”>
    <property name=”transactionManager”>
    <ref local=”transactionManager”/>
    </property>
    <property name=”target”>
    <ref local=”hotelManager”/>
    </property>
    <property name=”transactionAttributes”>
    <props>
    <prop key=”save*”>PROPAGATION_REQUIRED</prop>
    <prop key=”remove*”>PROPAGATION_REQUIRED</prop>
    <prop key=”*”>PROPAGATION_REQUIRED,readOnly</prop>
    </props>
    </property>
    </bean>

    #258003

    bansi
    Member

    @JeremyStein wrote:

    Going back to the problem in the original post, the issue was that Spring was never loaded. The second poster (avintis) suggested using ContextLoaderServlet, but it would be better to use ContextLoaderListener as listeners are loaded before servlets. So, this should be added to web.xml:

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

    By default, MyEclipse 5 (I’m not sure about 4) puts applicationContext.xml in src, which means it gets copied to WEB-INF/classes. Spring expects it to be in WEB-INF, so you have to also add this to web.xml to tell Spring where to find the file:

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

    In any case, it’s also a good idea to configure log4j, so that Spring can tell you when it has a problem (such as being unable to find its config file). Drop log4j.properties in src:

    log4j.rootCategory=INFO, stdout
    
    log4j.appender.stdout=org.apache.log4j.ConsoleAppender
    log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
    log4j.appender.stdout.layout.ConversionPattern=[@APPNAME@] %p [%t] %c{1}.%M(%L) | %m%n
    
    log4j.logger.org.springframework=WARN
    #258009

    Riyad Kalla
    Member

    bansi,
    Would you be able to creat a small sample project with just the necessary parts to see this bug and email it to me at support@genuitec.com ATTN Riyad? Also please include a link to this forum post so I know why I’m getting it.

    #258053

    Riyad Kalla
    Member

    bansi,
    Your examples files were helpful but not complete so I had to structure a project around them (some dummy classes). I would point out that I have no errors with any of these files:

    and

    and you can download my project to double check that it works with your install of MyEclipse.

    #258126

    bansi
    Member

    Hi Riyad
    Thank you so much for your help. I downloaded your project and noticed that ShowRooms.java under hotelReservations package has been made empty. Wondering whether this was the fix or is there something else which i am missing.
    Also ShowRooms.java is a JSF Backing Bean which uses Dependency Injection to inject Spring Beans i.e. manager in this example as shown below
    /**
    * Holds value of property hotelReservation.
    */
    private HotelManager manager;

    /**
    * Setter for property hotelManager.
    * @param hotelManager New value of property hotelManager.
    */
    public void setManager(HotelManager manager) {
    this.manager = manager;
    }

    public HotelManager getManager() {
    return manager;
    }
    Could you please tell me the changes you made to fix the problem. Also pl note the reference to this sample project is available at http://www.developer.com/java/ent/article.php/3602061

    Regards
    Bansi

    #258142

    Riyad Kalla
    Member

    Bansi,
    I’m sorry I don’t have time right at the moment to dig into that example project and figure out where the differences lay. If I get some time later this week I will, in the mean time let me know if you find anything out.

    #258152

    bansi
    Member

    Hi Riyad
    I have ran into new problem now. Here is the error from Tomcat Console
    Sep 5, 2006 2:31:27 PM org.apache.catalina.core.StandardContext start
    SEVERE: Error listenerStart
    Sep 5, 2006 2:31:27 PM org.apache.catalina.core.StandardContext start
    SEVERE: Context startup failed due to previous errors

    This happens only when i add listener to web.xml file
    <listener>
    <listener-class> org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    The moment i take off this line the error disapperas
    Pl suggest

    Regards
    Bansi

Viewing 15 posts - 1 through 15 (of 15 total)
Reply To: JSF and Spring

You must be logged in to post in the forum log in