【问题标题】:gsp mail plugin autosendinggsp 邮件插件自动发送
【发布时间】:2013-01-28 13:44:25
【问题描述】:

当我导航到页面时,为什么会自动调用 send() 函数?

我希望能够查看 gsp 页面,填写一些文本字段,然后使用“发送”操作调用提交

这是我的 gsp 文件

<%@ page contentType="text/html;charset=UTF-8" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
<meta name="layout" content="main"/>
<title>Contact Form</title>
</head>
<body>
<g:form name="contactForm" action = "send">
    <g:render template = "contactFormFields"/>
    <g:actionSubmit value = "submit" action = "send"/>
</g:form>
</body>
</html>

这是contactFormFields模板

<g:select name = 'subject' from = '${EmailService.options}' noSelection='Topic'/>

Contact Name: <g:textField name = "contact"/>
Contact Number: <g:textField name = "phone"/>
Contact Email: <g:textField name = "email"/>
Aditional Information:
<g:textArea name = "information" rows="5" cols="40"/>

电子邮件服务控制器

class EmailServiceController {

    def defaultAction = "contactService"

    def send() {
        sendMail(){
            to "mygroovytest@gmail.com"
            from params.email
            subject params.subject
            body params.information
        }
    }
}

域类

class EmailService {

    static constraints = {
        def options = new ArrayList()
        options.push("Qestions about service")
        options.push("Feedback on performed service")
        options.push("Other")
        options.push("Why am I doing this")
    }
}

调用服务的gsp

<div class="banner">
  <h1>My HVAC company</h1>
  <a href = "javascript: contactPop()"> Contact me today!</a>
  <a href = "services">Services</a>
  <a href = "emailService">Have Me Contact You!</a>
</div>

【问题讨论】:

  • 您能否添加更多关于加载此表单的操作的上下文?
  • @uchamp 我添加了域类和链接所在的 div

标签: grails controller grails-plugin gsp


【解决方案1】:

您的EmailServiceController 中没有contactService 操作,因此当您链接到没有操作名称的控制器时,它可能会将send() 视为默认操作。尝试添加一个空的contactService 操作

def contactService() { }

【讨论】:

  • 很好,但现在它说选项必须是一个集合(我还不知道该怎么做)。我试图使用 grails 来简化它的流程,但我知道它是一个全新的野兽
  • @MattWestlake 如上所述,您已将 options 声明为域类的 constraints 块内的局部变量(顺便说一下,名称非常糟糕 - 您应该只真正使用 @987654328 @ 服务后缀,而不是域类)。我不确定您到底想要实现什么,但如果选项列表是固定的,那么在 GSP 中内联声明它们或将它们放入 src/java 的枚举中可能更容易,而不是尝试使用域类。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-10-22
  • 2013-08-22
  • 1970-01-01
  • 1970-01-01
  • 2013-10-31
相关资源
最近更新 更多