Menu

How to uses JSF-Spring

Users
Kai Ulrich
2006-03-08
2013-04-08
  • Kai Ulrich

    Kai Ulrich - 2006-03-08

    Hallo,

    I'm new at JSF-Spring (... but I used Spring and JSF). So, I'm looking for some infoemation how to setup and use JSF-Spring. I looked at the jsf-spring-3.0.0M3-testsuite.war and the jsf-spring-3.0.0M3.zip. Its a lot of compact information. Before I start to dive into it,, here my question.
    Are the any Howto's, articles or tutorials about JSF-Spring ?

    Friendly regards
    Kai

     
    • Thomas Jachmann

      Thomas Jachmann - 2006-03-08

      Hi Kai,

      there isn't any tutorial or cookbook yet, but it is being worked on. The testsuite can't really be considered being any documentation, although it shows the use of all of jsf-spring's features. It's main purpose is to provide a mean to do testing, as the name suggests. Furthermore, it isn't functional at the moment. Expect a functional version with the release of 3.0.0 RC1 by the end of next week. We can't predict when the documentation will be released yet, but it will grow during the preparation of a talk we're giving at the jax in may. I'm off for a meeting now but I'll post a short walk-through to get you going later today.

      Cheers,
      Thomas

       
      • Kai Ulrich

        Kai Ulrich - 2006-03-08

        If you need help, tell me, I think about joining the documentation team. I'm an examinated teacher, I might be able to help.

        Greatings Kai

         
        • Thomas Jachmann

          Thomas Jachmann - 2006-03-08

          This is a great offer. We actually did plan to open up the team this year, anyway. So I'll discuss this with Wolfgang, who is responsible for documentation, and we'll see how things work out. Thanks for wanting to contribute.

          Cheers,
          Thomas

           
      • Thomas Jachmann

        Thomas Jachmann - 2006-03-08

        So here's the HowTo:

        1. You need to deploy the jars you want to use:
           - jsf-spring-core.jar the core framework
           - jsf-spring-context.jar integration of the the two IOC containers (JSF and Spring)
           - jsf-spring-config.jar (optional) needed when you want to configure JSF components (eg. converters) using Spring

        2. You need to activate jsf-spring by inserting the corresponding listener/servlet to your web.xml, depending on whether your servlet container supports listeners. See http://jsf-spring.sourceforge.net/3.0.0M3/de/mindmatters/faces/spring/context/package-summary.html for an example for jsf-spring-context (mandatory) and http://jsf-spring.sourceforge.net/3.0.0M3/de/mindmatters/faces/spring/config/package-summary.html for jsf-spring-config (optional).

        3. Create your configuration files:
        - WEB-INF/applicationContext.xml for Spring
        - WEB-INF/faces-context.xml for JSF
        - WEB-INF/faces-spring-context.xml for JSF managed beans that are configured using a spring compatible syntax
        - WEB-INF/faces-spring-config.xml for JSF components configured via jsf-spring-config

        faces-spring-context.xml can use the following doctype:
        <!DOCTYPE beans PUBLIC "-//JSF-SPRING//DTD BEAN//EN" "http://jsf-spring.sf.net/dtd/jsf-spring-beans.dtd">
        This will enable you to use the scope attribute in your bean definitions.

        If you want to split your configuration in several files, you have to specify them using the following context params:
        - contextConfigLocation
        - javax.faces.CONFIG_FILES
        - faces.spring.CONTEXT_FILES
        - faces.spring.CONFIG_FILES

        This should be it (from the top of my head...) - if you have problems, post your questions here.

        HTH,
        Thomas

         
        • Kai Ulrich

          Kai Ulrich - 2006-03-09

          It, workd fine.

          There is a little problem I got into,
          how can I inject objects into

          - ActionListener's
          - Validators
          - Converters

          Kai

           
          • Thomas Jachmann

            Thomas Jachmann - 2006-03-13

            You can use all of Spring's standard injection methods. Keep in mind that you cannot inject beans from all contexts, though, due to the way jsf-spring sets up the context hierarchy. You can use the beans defined in your faces-config.xml file (or those configured in web.xml) and in your spring applicationContext.xml. You cannot use those defined in your faces context.

            HTH,
            Thomas

             
    • Kai Ulrich

      Kai Ulrich - 2006-03-08

      Bye the way thenx for your help :-)

       
    • Kai Ulrich

      Kai Ulrich - 2006-03-08

      Hallo Thomas,
      thanx for your time.
      Kai

       
    • Shekhar Yadav

      Shekhar Yadav - 2006-03-31

      I did all the steps mentioned and I am getting this exception:

      javax.servlet.ServletException: Error calling action method of component with id LoginForm:submit
          javax.faces.webapp.FacesServlet.service(FacesServlet.java:121)

      root cause

      javax.faces.FacesException: Error calling action method of component with id LoginForm:submit
          org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:74)
          javax.faces.component.UICommand.broadcast(UICommand.java:106)
          javax.faces.component.UIViewRoot._broadcastForPhase(UIViewRoot.java:90)
          javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:164)
          org.apache.myfaces.lifecycle.LifecycleImpl.invokeApplication(LifecycleImpl.java:316)
          org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:86)
          javax.faces.webapp.FacesServlet.service(FacesServlet.java:106)

      In tomcat logs:

      Caused by: java.lang.NullPointerException
          at com.strongmail.view.LoginBean.login(LoginBean.java:69)

      where LoginBean.java has:
      ServletContext context =
              (ServletContext)FacesContext.getCurrentInstance().getExternalContext().getContext();
           ApplicationContext appContext =
              WebApplicationContextUtils.getWebApplicationContext(context);
           IAuth pAuth = (IAuth)appContext.getBean("AuthBean");

      and I define the bean in applicationContext.xml

      Is there anything that I am missing here?

       
    • Shekhar Yadav

      Shekhar Yadav - 2006-03-31

      I resolved the issue. web.xml configuration had no entry for jsf-spring listener (copy paste error) so I was getting null FacesContext.

      It is working pretty well now.

       

Log in to post a comment.