我的项目有问题,我正在使用spring,jsf和primefaces,问题是当我希望使用ajax请求调用方法时,我不能,并且没有错误消息可以帮助我找到问题是这是我第一次使用spring和带有注释的jsf配置。 请帮助我。
我的配置:
@Configuration
@ComponentScan
@EnableTransactionManagement
public class AppConfig {
@Bean
public DataSource dataSource() {
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName("com.mysql.jdbc.Driver");
dataSource.setUrl("jdbc:mysql://localhost:3306 /carouzetDb?useUnicode=true&useJDBCCompliantTimezoneShift=true& useLegacyDatetimeCode=false&serverTimezone=UTC");
dataSource.setUsername("root");
dataSource.setPassword("root");
return dataSource;
}
private Properties hibernateProperties() {
Properties hibernateProperties = new Properties();
hibernateProperties.setProperty(
"hibernate.hbm2ddl.auto", "create");
hibernateProperties.setProperty(
"hibernate.dialect", "org.hibernate.dialect.MySQL5Dialect");
return hibernateProperties;
}
@Bean
public LocalSessionFactoryBean sessionFactory() {
LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean();
sessionFactory.setDataSource(dataSource());
sessionFactory.setPackagesToScan("com.crouzet.carouzetroject.entities");
sessionFactory.setHibernateProperties(hibernateProperties());
return sessionFactory;
}
@Bean
public PlatformTransactionManager hibernateTransactionManager() {
HibernateTransactionManager transactionManager
= new HibernateTransactionManager();
transactionManager.setSessionFactory(sessionFactory().getObject());
return transactionManager;
}
}
public class MvcContentInitializer implements WebApplicationInitializer {
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
ctx.register(AppConfig.class);
ctx.setServletContext(servletContext);
servletContext.addListener(new ContextLoaderListener(ctx));
}
}
jsf配置: faces-config.xml
<?xml version='1.0' encoding='UTF-8'?>
<faces-config version="2.2"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd">
<application>
<el-resolver>
org.springframework.web.jsf.el.SpringBeanFacesELResolver
</el-resolver>
</application>
<render-kit>
<renderer>
<component-family>org.primefaces.component</component-family>
<renderer-type>org.primefaces.component.FileUploadRenderer</renderer-type>
<renderer-class>com.crouzet.carouzetroject.FileUploadRenderer</renderer-class>
</renderer>
</render-kit>
</faces-config>
这是我调用我的方法的示例:
@ManagedBean(name = "helloBean")
@ViewScoped
@Component
public class HelloBean {
List<Salarie> salaries;
List<Categorie> categories;
List<Poste> postes;
Production production;
Categorie selectedCat;
@Autowired
private CategorieDAO categorieDAO;
@Autowired
private SalarieDAO salarieDAO;
@PostConstruct
public void init(){
categories=categorieDAO.allCategories();
System.out.println("==========>>>FROM INIT"+categories.size());
}
public void actualiser(){
categories=categorieDAO.allCategories();
}
public void listeDesSalaries(){
System.out.println("========AAAAAAAAAAAAAA========>>>>");
if(selectedCat!=null)
salaries=salarieDAO.salariesParCategorie(selectedCat);
}
public List<Salarie> getSalaries() {
return salaries;
}
public void setSalaries(List<Salarie> salaries) {
this.salaries = salaries;
}
public List<Categorie> getCategories() {
return categories;
}
public void setCategories(List<Categorie> categories) {
this.categories = categories;
}
public List<Poste> getPostes() {
return postes;
}
public void setPostes(List<Poste> postes) {
this.postes = postes;
}
public Production getProduction() {
return production;
}
public void setProduction(Production production) {
this.production = production;
}
public Categorie getSelectedCat() {
return selectedCat;
}
public void setSelectedCat(Categorie selectedCat) {
this.selectedCat = selectedCat;
}
}
这是我的页面
<h:form>
<p:commandButton action="#{helloBean.actualiser()}" value="Actualiser" update="mesListes"/>
<p:panelGrid id="mesListes" columns="2">
<p:outputLabel value="Ligne de fabrication"/>
<p:selectOneMenu id="categori" value="#{helloBean.selectedCat}">
<f:selectItem itemLabel="Select One" itemValue="" />
<f:selectItems value="#{helloBean.categories}" var="cat" itemLabel="#{cat.nom}" itemValue="#{cat}" />
<p:ajax listener="#{helloBean.listeDesSalaries()}" />
</p:selectOneMenu>
</p:panelGrid>
</h:form>