从grails控制器调用引导弹出窗口 [英] Calling a Bootstrap popup from grails controller

查看:114
本文介绍了从grails控制器调用引导弹出窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要显示错误消息弹出窗口,如以下链接所示。它应该出现在页面顶部几秒钟,然后消失。

  if(!userInstance.save(flush: true)){

//错误弹出窗口应该从这里调用

返回
} else {
...
}

我应该在HTML中放置代码,我应该如何从GRAILS控制器调用它?例如,在你的控制器中:

pre $ def $ model $ ['userInstance'] = userInstance
...
if(!userInstance.save(flush:true)){
//设置/查找错误消息
model ['errorMessage'] = message(代码:'some.error.message.you.lookup')
//渲染视图
渲染(view:'theviewname',model:model)

return






然后你可以显示这在你的视图(或布局)中:

 < g:if test =$ {errorMessage}> 
< div class =class =alert alert-danger alert-dismissable> $ {errorMessage}< / div>
< / g:if>

因为这里的概念是最重要的部分,所以我会让它从图片中消失(jquery的一部分)。 / p>

希望这有帮助,欢迎来到Grails!


I need to display an error message popup as shown in the following link . It should appear on top of the page for a few seconds and then fade away.

if (!userInstance.save(flush: true)) {

    // THE ERROR POPUP SHOULD BE CALLED FROM HERE

    return
}else  {
   ...
}

Where should I place the code in my HTML and how should I call it from GRAILS controller?

解决方案

As with any view that displays data from a controller you should place this information into your model. I would recommend you settle on a standard element in your model to make this easier to implement for your entire project (which I assume is where you are headed).

So For example, in your controller(s):

def model = [:]
model['userInstance'] = userInstance
...
if (!userInstance.save(flush: true)) {
    // set/lookup the error message
    model['errorMessage'] = message(code: 'some.error.message.you.lookup')
    // render the view
    render(view: 'theviewname', model: model)

    return
}else  {
   ...
}

Then you can display this in your view (or layout):

<g:if test="${errorMessage}">
  <div class="class="alert alert-danger alert-dismissable">${errorMessage}</div>
</g:if>

I will leave the making it fade away (sprinkle of jquery) out of the picture since the concept here is the most important part.

Hope this helps, and welcome to Grails!

这篇关于从grails控制器调用引导弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆