Java Struts 2中未显示基于注释的验证消息

Java Struts 2中未显示基于注释的验证消息,java,hibernate,jsp,validation,struts2,Java,Hibernate,Jsp,Validation,Struts2,我正在我的项目中使用Struts 2基于注释的验证。这是我的实体类,只有我验证了一些字段 公共类供应商实现可序列化{ 私有字符串vendorName; 公共字符串getVendorName(){ 返回供应商名称; } @RequiredStringValidator(message=“VendorName是必需的”,type=ValidatorType.FIELD) 公共void setVendorName(字符串vendorName){ this.vendorName=vendorName;

我正在我的项目中使用Struts 2基于注释的验证。这是我的实体类,只有我验证了一些字段

公共类供应商实现可序列化{
私有字符串vendorName;
公共字符串getVendorName(){
返回供应商名称;
}
@RequiredStringValidator(message=“VendorName是必需的”,type=ValidatorType.FIELD)
公共void setVendorName(字符串vendorName){
this.vendorName=vendorName;
}
}
这是我的action类,它实现了模型驱动的接口

公共类AddVendorAction扩展ActionSupport实现模型驱动{
私人供应商v;
公共AddVendorAction(){
此.v=新供应商();
}
公共字符串保存(){
System.out.println(“hhhhhhhhhhwe”);
vd.addVendor(getV());
回归成功;
}
公共字符串populateItems(){
leftsideVendorlist=vd.itemSet();
回归成功;
}
公共字符串vendorList(){
vendorlist=vd.list();
回归成功;
}
公共供应商getV(){
返回v;
}
公共无效setV(供应商v){
这个,v=v;
}
公共列表getVendorlist(){
返回供应商列表;
}
公共无效设置供应商列表(列表供应商列表){
this.vendorlist=vendorlist;
}
@凌驾
公共供应商getModel(){
返回v;
}
}
这是我的
struts.xml
文件,它扩展了hibernate默认包


大众项目
卖主
/VendorList.jsp
/addvendor.jsp
/addvendor.jsp
这是我的jsp页面


供应商名称

它没有显示任何验证消息。我无法找出问题所在。有人能帮我吗。

您应该在
模型
属性上使用访问者字段验证程序

@Override
@VisitorFieldValidator(appendPrefix = false)
public Vendor getModel() {
    return v;
}

根据@Roman C给出的建议,像这样的更改有效吗?在我的操作类中添加了
@VisitorFieldValidator(appendPrefix=false)


在Jsp页面中添加了
,因为
input
结果不应该是
chain
它应该是
dispatcher
,如果你想填充列表,可以在
prepare()
方法中实现
preparable
或configure
input()
方法。非常感谢你,这对我帮助很大。谢谢你,我也看到了。在上面的jsp页面中,错误消息显示了两次,我不知道为什么。你可以通过查看代码再次帮助我吗?非常感谢你,在so中的帮助非常好。如果你使用默认(xhtml)主题,那么你不需要使用
s:fielderror
标记,xhtml主题添加了错误消息,
s:fielderror
也添加了消息。我尝试使用简单主题。
s:fielderror
也显示了两次消息。但是在上面的代码验证中,错误消息显示了两次,无法解释原因。有人能帮我吗。
@Override
@VisitorFieldValidator(appendPrefix = false)
public Vendor getModel() {
    return v;
}
public class AddVendorAction extends ActionSupport implements ModelDriven<Vendor>,Preparable {
 @Override
@VisitorFieldValidator(appendPrefix = false)
public Vendor getModel() {
    return v;
} 
@Override
public void prepare() throws Exception {
     leftsideVendorlist = vd.itemSet();
}
}
<action name="AddVendor" 
            class="com.elegant.purchasemodule.purchasemasters.vendor.AddVendorAction" 
            method="save">            
        <interceptor-ref name="defaultStack"/>
        <result name="input">/addvendor.jsp</result>
        <result name="success" type="redirect">vendorlist</result>
    </action>
<s:form  action="AddVendor" method="post" cssClass="form-horizontal" theme="simple">

 <label class="col-md-3 control-label" for="textinput">Vendor Name</label>  
 <s:textfield id="vendorName" name="vendorName" cssClass="form-control input-md"/> 
 <s:fielderror fieldName="vendorName" cssClass="alert-danger"/>
 </s:form>