我在grails webflow中预填充下拉列表时遇到问题
我有一个用于webflow的控制器
class ClearanceRequestController {
def index() {
redirect(action: "start")
}
def startFlow = {
contact {
on('next') {
flow.developer = params.developer
flow.project = params.project
flow.projectResponsible = params.projectResponsible
flow.email = params.email
[flow : flow]
}.to('application')
on('cancel').to('finish')
...
并且视图如下所示: contact.gsp
<g:if test="${message}">
<div class="message">${message}</div>
</g:if>
<g:form action="start" method="post">
<div class="dialog">
<table>
<tbody>
<tr class="prop">
<td valign="top" class="name">
<label for="projectName">Projekt:</label>
</td>
<td valign="top">
<input type="text" id="projectName" name="project" value="${params.project}" />
</td>
</tr>
<g:select name="state" from="${Project?.DIVISION_OPTIONS}" value="${Project?.DIVISION_OPTIONS}"/>
这是项目定义
class Project {
static DIVISION_OPTIONS = ["A", "B", "C", "D"]
String name
String division
String toString(){
"$name"
}
static constraints = {
name(unique: true)
division(inList: DIVISION_OPTIONS)
}
}
我不知道如何从约束中获取数据。我试图访问
Project.constraints.division.inList
或
Project.DIVISION_OPTIONS
但两者都没有奏效。我假设我必须在某处初始化Project并将其传递给contact.gsp,但我不知道如何。
答案 0 :(得分:1)
好的我明白了,只需在页面中导入Project
,就像
<%@ page import="com.companyName.Project" contentType="text/html;charset=UTF-8" %>
或者喜欢:
<g:select name="state" from="${com.companyName.Project?.DIVISION_OPTIONS}" value="${com.companyName.Project?.DIVISION_OPTIONS}"/>