我写了一个方法' init'注释PostConstruct
@ManagedBean
@ViewScoped
public class BrandController {
@ManagedProperty(value="#{carsService}")
private CarsService carsService;
private String name;
private String country;
private List<Brand> listBrands;
public BrandController() {
}
public void setListBrands(List<Brand> listBrands) {
this.listBrands = listBrands;
}
@PostConstruct
public void init()
{
setListBrands(carsService.listBrand());
}
//here is all setters and getters
}
我也
public interface CarsService
{
public void createBrand(Brand b);
public void deleteBrand(Brand b);
public List<Brand> listBrand();
}
以及此接口的实现
@Service("carsService")
@Transactional
public class CarSeviceImpl implements CarsService{
@Autowired
private BrandDao branDao;
public BrandDao getBranDao() {
return branDao;
}
public void setBranDao(BrandDao branDao) {
this.branDao = branDao;
}
@Override
public List<Brand> listBrand()
{
return branDao.listBrand();
}
@Override
public void createBrand(Brand b) {
branDao.createBrand(b);
}
@Override
public void deleteBrand(Brand b) {
branDao.deleteBrand(b);
}
}
我的brand.xhtml视图:
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title>brands</title>
</h:head>
<h:body>
<h:form id="formBrands">
<p:growl/>
<h:panelGrid columns="2" cellpadding="6">
<p:outputLabel value="Name" for="nameIn"/>
<p:inputText value="#{brandController.name}" required="true" requiredMessage="the input field name is empty" id="nameIn"/>
<p:outputLabel value="Coutry" for="countryIn"/>
<p:inputText value="#{brandController.country}" required="true" requiredMessage="the input field coutry is empty" id="countryIn"/>
<p:commandButton value="save" action="#{brandController.save}" update=":formBrands :formList"/>
</h:panelGrid>
</h:form>
<h:form id="formList">
<p:dataTable id="brandTable" value="#{brandController.listBrands}" var="brand" rowKey="#{brand.name}" rows="10"
emptyMessage="there is no brands" paginator="true" paginatorPosition="bottom">
<p:column headerText="name">
<h:outputText value="#{brand.name}"/>
</p:column>
<p:column headerText="country">
<h:outputText value="#{brand.country}"/>
</p:column>
</p:dataTable>
</h:form>
</h:body>
我收到这样的错误&#39;
在托管bean上执行资源注入时发生错误 brandController
&#39;当我尝试使用品牌视图运行我的webapp时......
你能告诉我我在做错什么吗?