프로젝트 3에서 Spring 3과 JSF 2를 사용하고 있으며 지금까지는 요청 및 세션 범위 만 사용하고 있습니다. 일부 JSF 빈에 뷰 범위을 사용하고 싶습니다 (여러 이유로).내 ManagedBeans에서 뷰 범위를 사용할 수 없습니다.
문제점은 JSF ManagedBean이 Serializable 인터페이스와 모든 특성을 구현해야한다는 점입니다.
Spring Bean Serializables (예 : VilleService ...)를 가져 오는 데 어려움이 있습니다. 더 이상 클래스를 직렬화 할 수 없어도 (최대 절전 클래스 또는 mysql ...) 계속 요청할 것이기 때문입니다.
public class VilleBean extends BaseBean implements Serializable {
private Ville ville;
private List<Ville> villes;
private VilleService villeService;
private PaysService paysService;
private Pays pays;
private List<Pays> payss;
private PojoConverter<Pays> paysConverter = null;
public VilleBean() {
ville = new Ville();
pays = new Pays();
}
public void setVilleService(VilleService villeService) {
this.villeService = villeService;
}
public void setPaysService(PaysService paysService) {
this.paysService = paysService;
}
// getters and setters for attributes : ville, pays, villes, payss
public void addVilleAction() {
ville.setPays(pays);
villeService.create(ville);
}
public void deleteVilleAction(Ville ville) {
villeService.delete(ville);
villes = villeService.readAll();
}
public void updateVilleAction() {
ville.setPays(pays);
villeService.update(ville);
}
public PojoConverter<Pays> getPaysConverter() {
this.paysConverter = new PojoConverter<Pays>(getPayss());
return this.paysConverter;
}
}
public abstract class BaseBean {
protected FacesContext context = FacesContext.getCurrentInstance();
protected MessageFactory msg;
protected static final Logger log = Logger.getLogger(BaseBean.class);
}
POJO :
public class Ville implements Serializable {
private int id;
private String intitule;
private Pays pays;
// setters and getters
}
public class Pays implements Serializable {
private int id;
private String intitule;
// setters and getters
}
서비스 인터페이스 :
public interface VilleService extends ICrud<Ville> {
}
서비스 IMPL :
public class VilleServiceBase implements VilleService {
private IDao<Ville> dao;
// getter and setter for dao
@Override
public List<Ville> readAll() throws Exception {
return dao.readAll();
}
@Override
public void create(Ville entity) throws Exception {
dao.create(entity);
}
//****
여기
은 일례이며
백분율 :
public interface ICrud<T> {
public java.util.List readAll() throws Exception;
public void create(T entity) throws Exception;
public void update(T entity) throws Exception;
//****
public interface IDao<T> {
public java.util.List<T> readAll();
public T create(T entity);
//****
public class DaoBase<T> extends org.springframework.orm.hibernate3.support.HibernateDaoSupport implements IDao<T> {
private final Class<T> type;
public DaoBase(Class<T> type) {
this.type = type;
}
@Override
public T load(int id) {
return (T) this.getHibernateTemplate().get(this.type, new Integer(id));
}
@Override
public T create(T entity) {
//****
this.getHibernateTemplate().save(entity);
return entity;
}
봄 콩 : spring.xml :
<!-- Ville Service Implementation -->
<bean id="villeServiceBase" class="commun.ref.crud.VilleServiceBase">
<property name="dao">
<ref bean="villeDao"/>
</property>
</bean>
<!-- Ville Service Proxy -->
<bean id="villeService" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="target">
<ref local="villeServiceBase"/>
</property>
<property name="proxyInterfaces">
<value>commun.ref.crud.VilleService</value>
</property>
<property name="interceptorNames">
<list>
<value>manageableServiceTransactionInterceptor</value>
<value>hibernateInterceptor</value>
</list>
</property>
</bean>
<bean id="villeDao" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="target">
<bean class="smile.util.DaoBase">
<constructor-arg>
<value>commun.ref.Ville</value>
</constructor-arg>
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
</bean>
</property>
<property name="proxyInterfaces">
<value>smile.util.IDao</value>
</property>
<property name="interceptorNames">
<list>
<value>hibernateInterceptor</value>
</list>
</property>
</bean>
JSF 구성 :면-config.xml 파일 :
<application>
<el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>
</application>
<application>
<variable-resolver>
org.springframework.web.jsf.DelegatingVariableResolver
</variable-resolver>
</application>
******
<managed-bean>
<managed-bean-name>villeBean</managed-bean-name>
<managed-bean-class>commun.ref.ui.VilleBean</managed-bean-class>
<managed-bean-scope>view</managed-bean-scope>
<managed-property>
<property-name>villeService</property-name>
<value>#{villeService}</value>
</managed-property>
<managed-property>
<property-name>paysService</property-name>
<value>#{paysService}</value>
</managed-property>
</managed-bean>
당신이 무엇을, 제발 말할 수 이것을 작동 시키려면.
나는 항상 villeService에 null을 반환있어 서비스를하지만, 경우에 과도를 사용하는 treied. – faissal
사실, deserialization 후에 실제로 null이됩니다. '일시적'은 직렬화되지 않음을 의미합니다. 어떤 JSF 구현을 사용하고 있습니까? – partlov
저는 MyFaces를 사용하고 있습니다 – faissal