D
D
Daniil Miroshnichenko2015-02-11 17:50:23
Java
Daniil Miroshnichenko, 2015-02-11 17:50:23

How to replace ViewScoped when integrating JSF and Spring?

Hello! I just recently started doing a training project using JSF + Spring. There was a problem.
JSF has a great bean scope called ViewScoped. The bean persists while the page is being displayed. Very suitable if there are a lot of ajax requests on the page.
And there is no need to mess around with sessions and there is no constant re-instance of the bean after each HTTP request (as with RequestScoped) ) and the problem is that there is no analogue of ViewScoped in Spring. And when using scope = request, with each ajax request, the bean is re-initialized, it is read from the database, etc.
What is the best way to solve this problem?
I saw a custom viewscope implementation just for my case https://github.com/michail-nikolaev/primefaces-spr...
But somehow it doesn't always work correctly (at least for me).

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
pashablya1, 2015-02-12
@pashablya1

Leave bean creation to jsf with its scoped.
I did this:
1. Integration of jsf with spring in faces-config

<application>
    <el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>
  </application>

2. Description of the bean and spring DI from the context
<managed-bean>
    <managed-bean-name>bean</managed-bean-name>
    <managed-bean-class>com.xyz.SuperBean</managed-bean-class>
    <managed-bean-scope>view</managed-bean-scope>
    <managed-property>
      <property-name>service</property-name>
      <value>#{newsService}</value>
    </managed-property>
  </managed-bean>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question