我正在使用Primefaces客户端bean验证,但它不起作用,错误消息消失。即使验证失败,也会调用侦听器。
样本-xhtml -
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:i="http://kd.impakt2/tags">
<h:head>
<h:outputStylesheet library="css" name="images.css" />
</h:head>
<h:body>
<h:form id="parentForm">
<p:growl id="msgs" sticky="true" ></p:growl>
<p:inputText value="#{myBean.selCar.name}"></p:inputText>
<p:commandButton value="Click Me" validateClient="true">
<p:ajax event="click" listener="#{myBean.callMe}"
update="msgs" process="@form"></p:ajax>
</p:commandButton>
</h:form>
</h:body>
Java——import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.faces.bean.ManagedBean;
import org.hibernate.Criteria;
import org.primefaces.event.SelectEvent;
import org.primefaces.model.DefaultTreeNode;
import org.primefaces.model.LazyDataModel;
import org.primefaces.model.SortOrder;
import org.primefaces.model.TreeNode;
@ManagedBean(name = "myBean")
public class MyBean {
Car selCar;
public Car getSelCar() {
return selCar;
}
public void setSelCar(Car selCar) {
this.selCar = selCar;
}
public MyBean() {
selCar = new Car();
}
public void callMe(){
System.out.println("Hi");
}
}
Car.java——
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.validation.constraints.Size;
import org.primefaces.component.export.Exporter;
@Entity
public class Car {
@Id
String id;
@Size(min=1,max=2)
String name;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
但这是可行的-
<p:commandButton value="Click Me" validateClient="true" action="#{myBean.callMe}">
调试后,我发现当监听器被调用时消息显示,但一旦它完成消息消失。
我使用-Primefaces 42.2.6 Jsf。(银鲈)tomcat 7
请帮帮我。谢谢。
通过将JSF 2.2.6降级到JSF 2.2.2,一切都开始工作了