JSF ManagedBean - the entered properties do not work correctly on STATE_SAVING_METHOD = client

I have a problem with two days and I canโ€™t get out of this.

The problem I am facing is using the MangedBean property after deserialization (I think).
The property (purchaseManager) is configured using Spring and uses the DAO, which extends MyBatis as a data map for interacting with the database.
In fact, the first time you access the page, the purchaseManager.getAll () method inside init () works fine.
When I try to call refreshList () as an action using a button, I have a NullPointerException on getSqlSession () inside the DAO.

Providing only the appropriate code, follow these steps:

@ManagedBean(name = "purchaseController") @ViewScoped public class PurchaseController implements Serializable{ @ManagedProperty(value = "#{purchaseManager}") private PurchaseManager purchaseManager; @PostConstruct public void init(){ purchaseManager.getAll(); } public void refreshList(){ purchaseManager.getAll(); } } public class PurchaseManagerImpl implements PurchaseManager, Serializable { PurchaseDAO purchaseDAO; public void getAll() { purchaseDAO.getAll() } } public class PurchaseDAOImpl extends SqlSessionDaoSupport implements PurchaseDAO, Serializable { public void getAll() { SqlSession session = getSqlSession(); // when the call comes from refreshList(), session is null session.selectList("PAYMENT.getAll", null); } } in web.xml <context-param> <param-name>javax.faces.STATE_SAVING_METHOD</param-name> <param-value>server</param-value> </context-param> 

If I change STATE_SAVING_METHOD to the server, the application works fine, but that is not what I want. The same thing if I make ManageBean as RequestScope, but it will also punish my requirements.

Thank you in advance for any help! Ermal

0
spring jsf managed-bean viewstate mybatis
Apr 3 2018-12-12T00:
source share
1 answer

It was decided to add the error <aop:scoped-proxy proxy-target-class="false" /> to the service / manager definition declared through Spring. This allows you to enter a fully serializable instance of the proxy.

 <bean id="purchaseManager" class="al.ozone.bl.manager.impl.PurchaseManagerImpl"> <property name="purchaseDAO" ref="purchaseDAO" /> <aop:scoped-proxy proxy-target-class="false" /> </bean> 

proxy-target-class="false" means that PurchaseManagerImpl already implements the interface. If set to true or omitted, you must use the CGLIB2 library.

Thus, JSF correctly takes data from the database using Spring + MyBatis.

Mystery (for me) at this point (more theoretical):

  • MyBatis object ( PurchaseDAOImpl ) and dataSource properly handled backstage?
  • Are they recreated or restored in every HTTP request?

Remember that I have STATE_SAVING_METHOD=client and BackingBean as ViewScope .
My goal is to make the server easier, because I expect a high number of user interactions.

 <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="${jdbc.driverClassName}" /> <property name="url" value="${jdbc.url}" /> <property name="username" value="${jdbc.username}" /> <property name="password" value="${jdbc.password}" /> <property name="poolPreparedStatements" value="true" /> <property name="defaultAutoCommit" value="false" /> </bean> 

Thank you so much for any light on this!

Consulted links:

Spring beans (controllers) and service references in terms of serialization

http://static.springsource.org/spring/docs/2.5.x/reference/beans.html#beans-factory-scopes-other-injection

http://www.infoq.com/presentations/Whats-New-in-Spring-3.0

0
Apr 04 2018-12-12T00:
source share



All Articles