gpt4 book ai didi

java - 使用 xml 进行 struts 验证

转载 作者:太空宇宙 更新时间:2023-11-04 14:04:46 24 4
gpt4 key购买 nike

这是我的 Action 类

public class DoctorsController extends ActionSupport implements ModelDriven<Doctor> {

private DoctorDao docDao = new DoctorDaoImpl();
private List<Doctor> listDoc = new ArrayList<Doctor>();
private Doctor doc = new Doctor();

public List<Doctor> getListDoc() {
return listDoc;
}

public void setListDoc(List<Doctor> listDoc) {
this.listDoc = listDoc;
}


public String excute() throws Exception {
return SUCCESS;

}

public String getDoctorView() {

return SUCCESS;
}

public Doctor getDoc() {
return doc;
}

public void setDoc(Doctor doc) {
this.doc = doc;
}



public String addDoctor() {

this.docDao.addDoctor(this.doc);
listDoc = docDao.listDoctor();
return SUCCESS;

}

@Override
public Doctor getModel() {
return doc;
}

public DoctorDao getDocDao() {
return docDao;
}

public void setDocDao(DoctorDao docDao) {
this.docDao = docDao;
}

}

这是我在数据库中保存医生的表单

<html>
<head>
</head>
<body>
<s:form action="saveDoctor" method="post">
<table>
<s:push value="doc">
<s:hidden name="id" />

<s:textfield name="firstName" label="First Name" />

<s:textfield name="lastName" label="Last Name" />


<s:textfield name="email" label="Email" />

<s:textfield name="fees" label="Fees" />

<s:select name="specialist" list="#@java.util.LinkedHashMap@{'Bone':'Bone','Heart':'Heart'}" />

<s:textfield name="chamber.city" label="City" />

<s:textfield name="chamber.zipCode" label="ZipCode" />
<s:textfield name="chamber.roadNum" label="Road Num" />
<s:textfield name="chamber.houseNum" label="House Num" />




<s:submit/>

</table>

</s:push>
</s:form>
</body>
</html>

这是我的 DoctorsController-validation.xml,用于验证医生电子邮件

<validators>
<field name="doc.email">
<field-validator type="requiredstring">

<message>Email can't be blank</message>

</field-validator>

</field>
</validators>

现在验证工作正常,因为如果“电子邮件”字段为空,操作将重定向到输入表单,但问题是我在输入表单中看不到任何验证消息。我应该看到类似“电子邮件不能为空”的消息,但我没有看到它。

最佳答案

试试这个

   <form name="doc">
<field property="email" depends="required,email">
<arg key="doc.email"/>
</field>
<field property="firstName" depends="required">
<arg key="doc.firstName"/>
</field>
</form>

这段代码对我有用。

关于java - 使用 xml 进行 struts 验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28980689/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com