2

Hello I am new in Griffon Framework I want to add Login feature in my application. Follow are my model,view and controller:

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)

class 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)

class 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())
    }
}

}

I want to update my SignIn View If username and password are empty with error message. I am able to get error message in my model but my view not update so Please help me.

@Note: I have added griffon validation plugin

Piyush Chaudhari
  • 962
  • 3
  • 19
  • 41

1 Answers1

1

You must process the errors property of the validateable (the model instance). This property contains a list of messages that can be used to display information back to the user, however you must choose which messages, as there may be many. Your current code is one step away from this as it has already triggered validation; now you just need to consume the messages and present them in the UI.

Andres Almiray
  • 3,236
  • 18
  • 28