This entry was posted on September 10, 2007 at 8:19 am and is filed under Java.
.
You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.
30 Responses to “Using Spring to Manage JSF Beans”
>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.
[...] 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. [...]
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)
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 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?
[...] . 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 [...]
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?
[...] 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 [...]
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.
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.
September 10, 2007 at 5:02 pm
Very useful post!
September 11, 2007 at 7:16 am
[...] Using Spring to Manage JSF Beans [...]
September 11, 2007 at 7:18 am
Looks useful - but how do you inject request parameters? In faces-config.xml, you can do:
id
#{param.id}
September 11, 2007 at 7:18 am
Try that again:
<managed-property>
<property-name>id</property-name>
<value>#{param.id}</value>
</managed-property>
September 11, 2007 at 11:29 am
>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.
September 11, 2007 at 2:16 pm
You got it Lars.
September 12, 2007 at 8:26 am
[...] Using Spring to Manage JSF Beans Update: See this post about a better alternative, using Spring to manage JSF Beans. (tags: spring jsf) [...]
September 22, 2007 at 10:28 pm
[...] 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. [...]
September 23, 2007 at 8:18 am
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)
September 28, 2007 at 8:09 am
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?
October 1, 2007 at 11:42 pm
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!
October 2, 2007 at 8:18 pm
gr8 article
October 4, 2007 at 6:21 pm
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!
October 20, 2007 at 11:50 am
@ 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
November 7, 2007 at 11:42 pm
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?
November 8, 2007 at 8:04 am
Mustafa, you can change the scope of bean at applicationContext.xml.
November 15, 2007 at 6:14 pm
[...] 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 [...]
November 22, 2007 at 12:43 pm
[...] . 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 [...]
December 2, 2007 at 8:44 pm
How will this translate in my applicationContext.xml?
baseBean
com.naptosa.web.jsf.BaseBean
application
visit
#{sessionScope.visit}
Will it be something like?
December 7, 2007 at 1:27 pm
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
December 7, 2007 at 1:54 pm
is there a problem with my use of code tag. some of my previous posting did not show up correct.
December 19, 2007 at 8:52 am
[...] Using Spring to Manage JSF Beans [...]
January 18, 2008 at 3:40 pm
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?
February 25, 2008 at 4:28 am
[...] 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 [...]
April 5, 2008 at 11:59 pm
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?
April 25, 2008 at 1:06 pm
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.
April 27, 2008 at 6:30 am
I am using Spring 2.5 to manage JSF beans the problem is all bean properties are null
April 30, 2008 at 12:24 pm
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?
May 24, 2008 at 4:51 pm
Hi webmaster!
August 2, 2008 at 10:29 pm
Very nice!!