gpt4 book ai didi

forms - 将_form.gsp模板从Grails 2导入到Grails3

转载 作者:行者123 更新时间:2023-12-02 15:17:53 27 4
gpt4 key购买 nike

我正在使用Grails 3.3.3,并为我的域类生成了 View 。震惊地看到_form.gsp文件的删除!现在,基本上可以使用create.gsp动态呈现表单,如下所示:

<!DOCTYPE html>
<html>
<head>
<meta name="layout" content="main" />
<g:set var="entityName" value="\${message(code: '${propertyName}.label', default: '${className}')}" />
<title><g:message code="default.create.label" args="[entityName]" /></title>
</head>
<body>
<a href="#create-${propertyName}" class="skip" tabindex="-1"><g:message code="default.link.skip.label" default="Skip to content&hellip;"/></a>
<div class="nav" role="navigation">
<ul>
<li><a class="home" href="\${createLink(uri: '/')}"><g:message code="default.home.label"/></a></li>
<li><g:link class="list" action="index"><g:message code="default.list.label" args="[entityName]" /></g:link></li>
</ul>
</div>
<div id="create-${propertyName}" class="content scaffold-create" role="main">
<h1><g:message code="default.create.label" args="[entityName]" /></h1>
<g:if test="\${flash.message}">
<div class="message" role="status">\${flash.message}</div>
</g:if>
<g:hasErrors bean="\${this.${propertyName}}">
<ul class="errors" role="alert">
<g:eachError bean="\${this.${propertyName}}" var="error">
<li <g:if test="\${error in org.springframework.validation.FieldError}">data-field-id="\${error.field}"</g:if>><g:message error="\${error}"/></li>
</g:eachError>
</ul>
</g:hasErrors>
<g:form resource="\${this.${propertyName}}" method="POST">
<fieldset class="form">
<g:render template="form"/>
</fieldset>
<fieldset class="buttons">
<g:submitButton name="create" class="save" value="\${message(code: 'default.button.create.label', default: 'Create')}" />
</fieldset>
</g:form>
</div>
</body>
</html>

我喜欢Grails 2中的实际表单模板,该模板分别列出了类的每个属性。自定义表单比较容易(例如,在表单页面上添加下拉菜单)。以下是Employee类 (_form.gsp)的示例:
<%@ page import="com.djamware.Employee" %>



<div class="fieldcontain ${hasErrors(bean: employeeInstance, field: 'email', 'error')} required">
<label for="email">
<g:message code="employee.email.label" default="Email" />
<span class="required-indicator">*</span>
</label>
<g:field type="email" name="email" required="" value="${employeeInstance?.email}"/>

</div>

<div class="fieldcontain ${hasErrors(bean: employeeInstance, field: 'created', 'error')} required">
<label for="created">
<g:message code="employee.created.label" default="Created" />
<span class="required-indicator">*</span>
</label>
<g:datePicker name="created" precision="day" value="${employeeInstance?.created}" />

</div>

<div class="fieldcontain ${hasErrors(bean: employeeInstance, field: 'name', 'error')} required">
<label for="name">
<g:message code="employee.name.label" default="Name" />
<span class="required-indicator">*</span>
</label>
<g:textField name="name" required="" value="${employeeInstance?.name}"/>

</div>

<div class="fieldcontain ${hasErrors(bean: employeeInstance, field: 'position', 'error')} required">
<label for="position">
<g:message code="employee.position.label" default="Position" />
<span class="required-indicator">*</span>
</label>
<g:textField name="position" required="" value="${employeeInstance?.position}"/>

</div>

<div class="fieldcontain ${hasErrors(bean: employeeInstance, field: 'salary', 'error')} required">
<label for="salary">
<g:message code="employee.salary.label" default="Salary" />
<span class="required-indicator">*</span>
</label>
<g:field name="salary" value="${fieldValue(bean: employeeInstance, field: 'salary')}" required=""/>

</div>

现在是的,我可以从Grails 2项目中借用 _form.gsp文件并随意编辑它,但是没有办法在Grails 3中生成表单吗?

编辑:另外,如果我无法生成表单,那我该如何自定义字段(例如,更改日期字段的格式或合并两个字段值)?

最佳答案

...but isn't there a way to just generate the form in Grails 3?



没有。

关于forms - 将_form.gsp模板从Grails 2导入到Grails3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49305573/

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