1

我的 Roo 生成的(Web MVC,Hibernate)Person 类有一个 @PreUpdate @PrePersist 方法,由我添加,用于在将用户数据存储到数据库之前加密密码。此方法比较密码和密码确认 (@Transient) 表单字段,如果它们相等,则加密密码。在 create.jspx 中一切正常。但是update.jspx 不会将passwordConfirmation 表单值传递给Person.passwordConfirmation。我哪里错了?

更新.jspx:

    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<div xmlns:field="urn:jsptagdir:/WEB-INF/tags/form/fields" 
xmlns:form="urn:jsptagdir:/WEB-INF/tags/form" 
xmlns:jsp="http://java.sun.com/JSP/Page" 
xmlns:spring="http://www.springframework.org/tags" version="2.0">
    <jsp:directive.page contentType="text/html;charset=UTF-8"/>
    <jsp:output omit-xml-declaration="yes"/>
    <form:update id="fu_ru_dp_person_domain_Person" 
    idField="idperson" modelAttribute="person" 
    path="/persons" 
    versionField="none" z="Qhcf0JCeZUC6aMA3/6/5aDbQ13g=">
...
        <field:input field="password" id="c_ru_dp_person_domain_Person_password" required="true" type="password"  z=""/>
        <field:input field="passwordConfirmation" id="c_ru_dp_person_domain_Person_passwordConfirmation" required="true" type="password" z=""/>

创建.jspx:

    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<div xmlns:c="http://java.sun.com/jsp/jstl/core" 
xmlns:field="urn:jsptagdir:/WEB-INF/tags/form/fields" 
xmlns:form="urn:jsptagdir:/WEB-INF/tags/form" 
xmlns:jsp="http://java.sun.com/JSP/Page" 
xmlns:spring="http://www.springframework.org/tags" version="2.0">
    <jsp:directive.page contentType="text/html;charset=UTF-8"/>
    <jsp:output omit-xml-declaration="yes"/>
    <form:create id="fc_ru_dp_person_domain_Person" 
    modelAttribute="person" path="/persons" 
    render="${empty dependencies}" z="+YEbyTqiV2xT0u7rtPVJy3fd4Zw=">
        ...
        <field:input field="password" id="c_ru_dp_person_domain_Persons_password" required="true" type="password" z=""/>
        <field:input field="passwordConfirmation" id="c_ru_dp_person_domain_Person_passwordConfirmation" required="true" type="password" z="user-managed"/>

人.java:

 @PrePersist
    @PreUpdate
    protected void encryptPassword() {
        String pwd = this.getPassword(), pwd2 = this.getPasswordConfirmation();
        if (pwd2 != null && pwd.equals(pwd2)) {
            this.setPassword(passwordEncoder.encodePassword(pwd, null));
        }
    }
4

0 回答 0