【发布时间】:2014-05-28 22:17:32
【问题描述】:
我正在尝试在提交之前验证表单,但没有按预期工作。
这是我的 XHTML
<h:outputLabel for="name">Name: </h:outputLabel>
<p:inputText id="name" value="#{partyCreationBean.name}" />
<h:message for="name"/>
<h:outputLabel for="symbol">Symbol: </h:outputLabel>
这是我的 webBean:
@ManagedBean(name = "partyCreationBean")
@RequestScoped
public class PartyCreationBean {
@EJB
PartyManagerLocal ejb_partymanager;
@EJB
AuthenticationManagerLocal ejb_user;
private PartyDTO party = new PartyDTO();
public String getName() {
return party.getName();
}
public void setName(String name) {
party.setName(name);
}
这是我的 DTO:
import org.hibernate.validator.constraints.*;
public class PartyDTO implements IDataTransferObject {
private Integer id;
@NotEmpty()
private String name;
//Getters, setters and other stuff.
}
现在的重点是,如果我将“名称”留空并按下按钮来创建我的派对,页面将保持不变,并且我在控制台堆栈跟踪中出现异常(很像往常:D)
我尝试使用这个 XHTML(添加 require="true"):
<h:outputLabel for="name">Name: </h:outputLabel>
<p:inputText id="name" required="true" value="#{partyCreationBean.name}" />
<h:message for="name"/>
<h:outputLabel for="symbol">Symbol: </h:outputLabel>
它运行良好,但我想将我的“约束”放在 DTO 级别......
提前致谢:)
【问题讨论】:
标签: validation jsf bean-validation hibernate-validator