Primefaces客户端bean验证不起作用

时间:2014-05-21 10:25:10

标签: java jsf jsf-2 primefaces

我正在使用Primefaces客户端bean验证,但它无效,错误消息消失。即使验证失败,也会调用Listener。

的Sample- 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>

爪哇 -

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) tomcat 7

请帮帮我。感谢。

1 个答案:

答案 0 :(得分:0)

通过将JSF 2.2.6降级为JSF 2.2.2

,一切开始起作用