gpt4 book ai didi

validation - Grails框架中的文本字段验证

转载 作者:行者123 更新时间:2023-12-02 14:42:38 25 4
gpt4 key购买 nike

我是新来的。我想验证一个文本字段并在屏幕上抛出错误消息。谁可以帮我这个事。没有输入eg.lastName。

这是我的代码
人格
类人{

String firstName
String lastName
int age
static constraints = {
lastName(nullable:false, blank:false)
}

gsp



    <label for="firstName">FirstName</label>
<g:textField name="firstName" value="${person.firstName}"></g:textField><br/>
<label for="age">Age</label>
<g:textField name="age" value="${person.age}"/><br/>
<g:actionSubmit value ="save" action="save"/>

我尝试了上面,但没有用。我需要对验证进行任何设置吗?我正在intelliJ中尝试

最佳答案

您的代码可以正常工作
您没有处理任何错误,则至少应使用一些东西来在出现错误时闪现消息。
您可能想尝试这样的事情:

 <g:textField name="firsname" value="${person.firstname}"/>
<g:hasErrors bean="${person}" field="firstname">
<g:eachError bean="${person}" field="firstname">
<p style="color: red;"><g:message error="${it}"/></p>
</g:eachError>
</g:hasErrors>

关于validation - Grails框架中的文本字段验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26278796/

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