请问在jsf manager-property中可以直接引用spring 创建的 bean 吗?

06-03-21 xxxzheng
这是我的face-config.xml 中一段

<managed-bean>

<managed-bean-name>mtb</managed-bean-name>

<managed-bean-class>jobcn.view.bean.ManagerTelBean</managed-bean-class>

<managed-bean-scope>request</managed-bean-scope>

<managed-property >

<property-name>moduletelservice</property-name>

<value>#{moduletelservice}</value>

</managed-property>

</managed-bean>

我想用这样的方式来注入spring 创建的moduletelservice bean .但是我的这样尝试没有成功.

运行程序时候我的moduletelservice is null

我applicationContext.xml加载时候日志说明能成功创建moduletelservice.迷惘了半天哦....请高手指点下

我源程序

/**

* @author Steve

*

*/

package jobcn.view.bean;

import java.util.ArrayList;

import java.util.List;

import org.apache.commons.logging.*;

import jobcn.model.domain.telInfo;

import jobcn.model.exception.telException;

import jobcn.model.service.telService;

import jobcn.model.service.impl.telServiceImpl;

public class ManagerTelBean {

private telService moduletelservice ;

private Log logger = LogFactory.getLog(this.getClass());

private serviceLocatorBean servicelocatorbean;//这个bean 是我用间接的方式来得到moduleservice bean ;能成功。

/**

* @return Returns the servicelocatorbean.

*/

public serviceLocatorBean getServicelocatorbean() {

return servicelocatorbean;

}

/**

* @param servicelocatorbean The servicelocatorbean to set.

*/

public void setServicelocatorbean(serviceLocatorBean servicelocatorbean) {

this.logger.debug("service locator is set");

this.servicelocatorbean = servicelocatorbean;

}

/**

* @return Returns the moduletelservice.

*/

public telService getModuletelservice() {

return moduletelservice;

}

/**

* @param moduletelservice The moduletelservice to set.

*/

public void setModuletelservice(telService moduletelservice) {

this.moduletelservice = moduletelservice;

}

public List getAllTelList(){

List list = new ArrayList();

//这里就是我的判断,判断结果是null.所以需要用额外的方法来得到这个moduletelservice.

if(moduletelservice==null){

this.logger.info("moduletelservice is null");

// moduletelservice= new telServiceImpl();

moduletelservice = this.getServicelocatorbean().getModuletelservice();//

this.logger.info("new moduletelservice");

}

else{this.logger.info("moduletelservice is not null");

}

try {

list = moduletelservice.getAllTelList();

} catch (telException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

return list;

}

public telInfo getTelInfoById(int id){

telInfo tel = null;

try {

tel = moduletelservice.getTelByID(id);

} catch (telException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

return tel;

}

}

猜你喜欢