【问题标题】:Griffon Update Model and View From ControllerGriffon 从控制器更新模型和视图
【发布时间】:2015-09-30 03:46:01
【问题描述】:

您好,我是 Griffon 框架的新手,我想在我的应用程序中添加登录功能。以下是我的模型、视图和控制器:

SignInModel.groovy

@ArtifactProviderFor(GriffonModel)
@griffon.transform.Validateable
class SignInModel {
    @Bindable String userName
    @Bindable String password
static CONSTRAINTS = {
    userName(blank: false,nullable: false)
    password(blank: false, nullable: false)
}

}

SignInView.groovy

@ArtifactProviderFor(GriffonView)

类 SignInView {

FactoryBuilderSupport builder
SignInModel model
SignInController controller
void initUI() {
builder.with {
        application{
frame(title: 'Login', size: [330, 230],
                    show: true,resizable:false,locationRelativeTo: null,
                    defaultCloseOperation: EXIT_ON_CLOSE) {
                panel(constraints: BorderLayout.CENTER,
                        border: compoundBorder([emptyBorder(10),titledBorder('Welcome To Tracker')])) {
tableLayout() {
                        tr {
                            td {
                                label(text: "Username")
                            }
                            td {
                                textField(id: "usernameTxt", columns: 15, text: bind(target: model, 'userName', mutual: true))
                            }
                        }
                        tr{
                            td{
                                label(text:"Password")
                            }
                            td{
                                passwordField(id:"passwordTxt",columns:15,text:bind(target:model,'password',mutual:true))

                            }
                        }
                    }
                }
panel(constraints: BorderLayout.SOUTH) {
                    button text: 'Login', actionPerformed: {
                        model?.getErrors()?.clearAllErrors()
                        controller.signIn()
                    }
                }
}
            }
        }
}
}

}

SignInController.groovy

@ArtifactProviderFor(GriffonController)

类 SignInController {

SignInModel model
SignInView view
void signIn(){
    try {
if (model?.validate()) {
            println("No Error Found..")
        } else {
    println("Error Found..")
        }
}catch (Exception ex){
        println("Exception Generated:>>>>>>>>>>>>>>"+ex?.getMessage())
    }
}

}

如果用户名和密码为空并显示错误消息,我想更新我的登录视图。我可以在我的模型中收到错误消息,但我的视图没有更新,所以请帮助我。

@注意:我添加了 griffon 验证插件

【问题讨论】:

    标签: swing groovy griffon grails-validation


    【解决方案1】:

    您必须处理可验证对象(模型实例)的errors 属性。此属性包含可用于向用户显示信息的消息列表,但是您必须选择哪些消息,因为可能有很多。您当前的代码距此仅一步之遥,因为它已经触发了验证;现在您只需要使用这些消息并将它们呈现在 UI 中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-03-25
      • 2015-03-16
      • 2016-05-14
      • 1970-01-01
      • 1970-01-01
      • 2011-12-28
      • 2012-08-23
      • 1970-01-01
      相关资源
      最近更新 更多