Cagatay Civici’s Weblog

“Real power can’t be given, it must be taken”

Using Spring to Manage JSF Beans

Posted by cagataycivici on September 10, 2007

I’ve moved my blog, the link for the actual post is;

http://prime.com.tr/cagataycivici/?p=92

30 Responses to “Using Spring to Manage JSF Beans”

  1. Rogério Araújo Says:

    Very useful post!

  2. Integrating JSF and Spring « Cagatay Civici’s Weblog Says:

    [...] Using Spring to Manage JSF Beans [...]

  3. Matt Raible Says:

    Looks useful - but how do you inject request parameters? In faces-config.xml, you can do:

    id
    #{param.id}

  4. Matt Raible Says:

    Try that again:

    <managed-property>
    <property-name>id</property-name>
    <value>#{param.id}</value>
    </managed-property>

  5. Lars Ködderitzsch Says:

    >Looks useful - but how do you inject request parameters? In faces-config.xml, you can do:

    One could extend a Springs org.springframework.beans.factory.config.PropertyPlaceholderConfigurer which accesses the RequestContext (org.springframework.web.context.request.RequestContextHolder#getRequestAttributes()) to resolve ${xyz}-like properties in the bean.
    Of course that would only work for Spring beans with “request”-scope.

  6. cagataycivici Says:

    You got it Lars.

  7.   links for 2007-09-12 by The Third Part Says:

    [...] Using Spring to Manage JSF Beans Update: See this post about a better alternative, using Spring to manage JSF Beans. (tags: spring jsf) [...]

  8. Usando o Spring para gerenciar beans do JSF at JavaServer Faces e outras coisas mais… Says:

    [...] Eu estava conversando alguns dias atrás com um colega commiter do projeto MyFaces sobre padrões de projeto, melhores práticas e etc, em um dado momento ele me disse da possibilidade de se definir beans no Spring que podiam ser usados dentro do JSF obtendo o mesmo resultado quando se define um bean no faces-config.xml porém com todo um suporte de AOP e outras funcionalidades que só se encontram no Spring. Maiores detalhes aqui. [...]

  9. terry Says:

    I have try it, but there something make me puzzled. I use Spring’s IOC manage the bean, and put a JSF’s ActionListener in it. Then I click a button on the page to trigger the Listener, it carried out twice!!!Besides when I refresh the page, it also run two times!!!! It’s weird!!Can you help me~~~Thank you.
    (Myfaces1.20+Spring2.06)

  10. SpecialAgent Says:

    Hey there,

    nice soltion. In my simple test app it works pretty fine. But I don’t trust it if my app is growing big. Im not a JSF expert, but what about the other stuff that I can configure in the faces-context.xml, managed-bean tag?

    Do you know about the MyFaces Orchestra project? It uses a similar solution and has some other stuff… maybe this is the better way?

    What do you think?

  11. Paulo Melo Says:

    Hello Guys! When i deployed my applicattion in TomCat, the same throw the following error:
    SEVERE: Error listenerStart

    Why?

    What the spring version used in example? What the JSF implementation used in example?

    Thank you all!

  12. prabhanjan Says:

    gr8 article

  13. pal Says:

    Hello.
    Pretty cool stuff. I followed the steps, but my saveDVD-Method is not called (without error messages). Any ideas why?

    I appreciate any hints!

  14. bon quan Says:

    @ Pal
    I run into the same problem.
    When you change applicationContext.xml,
    you have to clean the tomcat work directory.Then it works

    @ Cagataycivici
    Really cool stuff

  15. Mustafa Sait Özen Says:

    What about JSF Bean’s scope? This method only works with JSF bean in request scope, doesn’t it?
    If there is a way change JSF bean scope by using this method, how can it be implemented?

  16. Adam Simone Says:

    Mustafa, you can change the scope of bean at applicationContext.xml.

  17. Springification « Standard Portlet Collection Project 7 Says:

    [...] which renders Spring unuseful for the view part. I even tried to follow the solution of http://cagataycivici.wordpress.com/2007/09/10/using-spring-to-manage-jsf-beans/. It did not work either. I suppose that maybe ICEFaces and/or Liferay destroy the request [...]

  18. (Not) Simple JSF+Spring « My Name is Gunna Says:

    [...] . I create a simple hello world project using my eclipse ide after following instruction from the tutorial i found. try running it using jetty 5 and the result is it didn’t work.. i found [...]

  19. pok Says:

    How will this translate in my applicationContext.xml?

    baseBean
    com.naptosa.web.jsf.BaseBean
    application

    visit
    #{sessionScope.visit}

    Will it be something like?

  20. Engin Ertilav Says:

    hi,

    is there a difference between the request scope of JSF managed and Spring managed beans? here is an example:

    i have a backing bean named accountbacking. and this bean has an another bean named account.

    i define both them in spring context as:

    at JSF(iceface components) page i am using valuechangelistener of an item. whenever this event is invoked these beans are re-created. i have defined init methods to observe this. they both called at page start and event trigger.

    then i moved accountbacking bean to faces-config file as:(account bean remains at spring context)

    accountbacking

    com.mypack.AccountBacking

    request

    account
    #{account}

    at this time i observed that accountbacking is created at page startup, so does account bean. at valuechangelistener they don’t re-created.

    so i have an opinion of difference between jsf and spring request beans. am i missing something?

    thanks in advance.

    Regards. Engin

  21. Engin Ertilav Says:

    is there a problem with my use of code tag. some of my previous posting did not show up correct.

  22. Annotate JSF Beans with Spring 2.5 « Cagatay Civici’s Weblog Says:

    [...] Using Spring to Manage JSF Beans [...]

  23. Seshu Says:

    When i try to deploy this on Weblogic 8.1 i get java.lang.NoClassDefFoundError: javax/servlet/ServletRequestListener

    is it because of servlet spec difference?

  24. Rafael Ponte » Blog Archive » Aproveitando os beans do Spring em suas páginas JSF Says:

    [...] bem bacanas. Nessa conversa ele chegou com uma idéia bem interessante sobre aproveitarmos a integração do Spring com JSF, a idéia se resume em aproveitar o variable resolver do Spring nas páginas JSF, assim poderíamos [...]

  25. Hussain Says:

    Hello,

    When I try to run this example with netbeans it does not run for me.

    I get the following error.

    HTTP Status 503 -

    ——————————————————————————–

    type Status report

    message

    descriptionThe requested service () is not currently available.

    ——————————————————————————–

    Sun Java System Application Server 9.1_01

    Can anyone point me in the right direction?

  26. sirisha Says:

    Hi,
    I don’t whether this is the correct blog to post my problem or not…

    this is related to jsf bean scope.my requirement is I have list of records in a datatable with radio button.when ever I select the radio button and when I click on edit link,it should open a modal window and populate the value in that window.I have created a bean which is there in the request.

    my problem is
    when I click on edit link the bean is created two time so the values are lost. I have to put the bean in request only..how can I stop creating the object for second time.

    Thanks.

  27. Anonymous Says:

    I am using Spring 2.5 to manage JSF beans the problem is all bean properties are null

  28. Jay Says:

    Excellent post.

    One question:

    Suppose i am using “Using Spring to Manage JSF Beans”, and my target jsf is different from source jsf. Then how does Spring come to know to which target jsf should it redirect if the target jsf is different?

    Since we are not using the conventional managed bean approach here we dont have the definied in faces-config.xml which would give us the details related to the target jsf.

    Please advice if my understanding is wrong?

  29. Kazeleza Says:

    Hi webmaster!

  30. RigVoineRed Says:

    Very nice!!

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>