java-Primefaces客户端bean验证不起作用
作者:互联网
我正在使用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 4
JSF 2.2.6(Mojarra)
雄猫7
请帮帮我.谢谢.
解决方法:
通过将JSF 2.2.6降级到JSF 2.2.2,一切都开始了
标签:java,jsf,primefaces,jsf-2 来源: https://codeday.me/bug/20191010/1885369.html