【问题标题】:Play framework Scala validation播放框架 Scala 验证
【发布时间】:2015-02-27 08:52:41
【问题描述】:

我正在尝试实现密码更改。

我在scala中得到了以下两行。但是,即使我在两个字段中输入不同的密码(PasswordConfirm Password),它也会保存第一个字段密码而不进行验证。

如果输入了不同的密码,我需要它来验证并显示消息。

@helper.inputPassword(accountForm("Password"),'id -> "f_password", '_label -> "Password", 'placeholder -> "**********")
@helper.inputPassword(accountForm("Password"),'id -> "f_password", '_label -> "Confirm Password", 'placeholder -> "**********")

我已经用谷歌搜索了,但似乎找不到确切的解决方案。非常感谢任何帮助。

更新

我在NewPasswordController.java的控制器中有如下方法

public class NewPasswordController extends Controller {
    public static class NewPassword {
    @Required
    protected String newPassword = "";
    @Required
    protected String confirmPassword = "";

    public String getNewPassword() { return this.newPassword; }

    public void setNewPassword(String newPassword) { this.newPassword = newPassword; }

    public String getConfirmPassword() { return this.confirmPassword; }

    public void setConfirmPassword(String confirmPassword) { this.confirmPassword = confirmPassword; }

    public String validate() {
        if(!newPassword.equals(confirmPassword)) {
            return "Opps, it seems that you may have mis-typed the password, please try again.";
        }
        return null;
    }
}

但我不确定如何在我的 SCALA 中使用它。

我已经尝试过如下

@helper.form(action = routes.NewPasswordController.NewPassword()) {

但这不起作用,因为我的路线文件没有。所以,我不确定如何在路由中提及 NewPasswordController(我的意思是它是 get 还是 set)。

【问题讨论】:

  • 为什么PaswordConfirm password 输入使用相同的accountForm 字段?

标签: java scala playframework template-engine play-helpers


【解决方案1】:

不知道你使用的那种方式是否真的有效, 但我认为您需要两个密码输入

@helper.inputPassword(accountForm("password"),'id -> "f_password", '_label -> "Password", 'placeholder -> "**********")
@helper.inputPassword(accountForm("confirmPassword"),'id -> "r_password", '_label -> "Confirm Password", 'placeholder -> "**********")

你的accountForm 需要这样的东西

public String confirm() {
    if (passwod!=confrimPassword) {
        return "password did not match";
    }
    return null;
}//offcourse you can convert into scala

【讨论】:

  • 实际上我的控制器中有这个方法,当我尝试它时,它给了我一个错误。我会更新这个问题。请通过。
  • @MissMintox 我在等
  • 我很抱歉延迟回答。我整整一个星期都没有工作,没有开始工作。我现在已经更新了。请看一看。
  • 你能看看这个链接吗? stackoverflow.com/questions/29140127/…
猜你喜欢
  • 2014-07-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-05-03
  • 2013-10-16
  • 2012-04-16
  • 1970-01-01
  • 2015-08-03
相关资源
最近更新 更多