【发布时间】:2014-12-26 08:05:33
【问题描述】:
我在我的项目中使用基于 Struts 2 注释的验证。这是我的实体类,仅在此我验证了一些字段
public class Vendor implements Serializable {
private String vendorName;
public String getVendorName() {
return vendorName;
}
@RequiredStringValidator(message = "VendorName is Required", type = ValidatorType.FIELD)
public void setVendorName(String vendorName) {
this.vendorName = vendorName;
}
}
这是我实现模型驱动接口的动作类
public class AddVendorAction extends ActionSupport implements ModelDriven<Vendor> {
private Vendor v;
public AddVendorAction() {
this.v = new Vendor();
}
public String save() {
System.out.println("hhhhhhhhhWE");
vd.addVendor(getV());
return SUCCESS;
}
public String populateItems() {
leftsideVendorlist = vd.itemSet();
return SUCCESS;
}
public String vendorList() {
vendorlist = vd.list();
return SUCCESS;
}
public Vendor getV() {
return v;
}
public void setV(Vendor v) {
this.v = v;
}
public List<Vendor> getVendorlist() {
return vendorlist;
}
public void setVendorlist(List<Vendor> vendorlist) {
this.vendorlist = vendorlist;
}
@Override
public Vendor getModel() {
return v;
}
}
这是我的 struts.xml 文件,它扩展了 hibernate-default 包
<struts>
<package name="purchasemodule" namespace="/" extends="hibernate-default">
<action name="AddVendor" class="com.elegant.purchasemodule.purchasemasters.vendor.AddVendorAction"
method="save">
<interceptor-ref name="defaultStack" />
<result name="input" type="chain">populateitems</result>
<result name="success" type="redirect">vendorlist</result>
</action>
<action name="vendorlist" class="com.elegant.purchasemodule.purchasemasters.vendor.AddVendorAction"
method="vendorList">
<result name="success">/VendorList.jsp</result>
</action>
<action name="populateitems" class="com.elegant.purchasemodule.purchasemasters.vendor.AddVendorAction"
method="populateItems">
<result name="success">/addvendor.jsp</result>
<result name="input" >/addvendor.jsp</result>
</action>
</package>
</struts>
这是我的jsp页面
<form action="AddVendor" method="post" class="form-horizontal" >
<label class="col-md-3 control-label" for="textinput">Vendor Name</label>
<s:textfield name="vendorName" cssClass="form-control input-md"></s:textfield>
</form>
它没有显示任何验证消息。我无法找出问题所在。任何人都可以帮助我。
【问题讨论】:
标签: java hibernate jsp validation struts2