Boa tarde senhores.
Estou com uma dúvida que ainda não consegui resolver.
Preciso que o JSF não chame o construtor vazio de uma classe pois o construtor que deve ser chamado no inicio do ciclo de vida é gerenciado pelo spring utilizando autowired=constructor.
O spring inicializa o objeto corretamente, porém o JSF vem depois e chama o padrão e isso apaga os itens que foram coletados antes pois é um managed-bean com escopo request.
Seguem as classes p uma idéia melhor.
package br.com.ibid.view;
import br.com.ibid.dto.CustomerDTO;
import br.com.ibid.service.CustomerService;
import java.util.List;
/**
*
* @author lgertel
*
*/
public class ListCustomers {
private CustomerService customerService;
private List<CustomerDTO> customers;
public ListCustomers() {
System.out.println("DEFAULT");
System.out.println(this.customers);
}
public ListCustomers(CustomerService customerService) {
this.customerService = customerService;
this.customers = this.customerService.findAll();
System.out.println("NON DEFAULT");
System.out.println(this.customers);
}
public List<CustomerDTO> getCustomers() {
// this.customers = this.customerService.findAll();
return customers;
}
public void setCustomers(List<CustomerDTO> customers) {
this.customers = customers;
}
public CustomerService getCustomerService() {
return customerService;
}
public void setCustomerService(CustomerService customerService) {
this.customerService = customerService;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<bean id="customerService" class="br.com.ibid.service.CustomerServiceImpl" autowire="constructor"/>
<bean id="listCustomers" class="br.com.ibid.view.ListCustomers" autowire="constructor" />
</beans>
<?xml version='1.0' encoding='UTF-8'?>
<!-- =========== FULL CONFIGURATION FILE ================================== -->
<faces-config version="1.2"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd">
<managed-bean>
<managed-bean-name>listCustomer</managed-bean-name>
<managed-bean-class>br.com.ibid.view.ListCustomers</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
<managed-property>
<property-name>customerService</property-name>
<value>#{customerService}</value>
</managed-property>
</managed-bean>
<application>
<el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>
</application>
</faces-config>
Agradeço de antemão.
Abraços,