我试图集成spring和JSF(Primefaces)。我使用@component注释将spring控制器配置为组件,以用作JSF bean,但未调用commandbutton的action方法。
XHTML文件:
<h:form id="productForm" >
<h:panelGrid columns="1">
<p:outputLabel for="name" value="Name: " />
<p:inputText id="name" value="#{cust.customerForm.name}" />
<p:outputLabel for="address" value="address" />
<p:inputNumber id="address" value="#{cust.customerForm.address}" />
<p:outputLabel for="email" value="Email: " />
<p:inputNumber id="email" value="#{cust.customerForm.email}" />
<p:outputLabel for="mobile" value="Mobile: " />
<p:inputNumber id="mobile" value="#{cust.customerForm.mobile}" />
<p:commandButton value="Save" action="#{cust.save}" />
</h:panelGrid>
</h:form>
用作JSF Bean的Spring控制器:
@Scope(value="session")
@Component(value = "cust")
@ELBeanName(value = "cust")
@Controller
@RequestMapping("/customer")
public class CustomerController {
@Autowired
private CustomerRepository customerRepo;
private List<Customer> customerList;
private Customer customerForm;
public List<Customer> getCustomerList() {
return customerList;
}
public Customer getCustomerForm() {
return customerForm;
}
public void setCustomerForm(Customer customerForm) {
this.customerForm = customerForm;
}
public String save(){
System.out.println("save called:::::::::::");
return("Customer");
}
}
请帮助我找出我在做什么错。
答案 0 :(得分:0)
您需要在org.springframework.web.jsf.el.SpringBeanFacesELResolver
中配置faces-config.xml
。否则,JSF找不到春豆。
当结合使用JSF和 Spring Boot 时,您应该定义尝试Joinfaces的方法(确实可以使它(以及其他一些有用的东西))