Spring Roo update.jspx @Transient密码字段

时间:2012-05-29 22:03:14

标签: java hibernate model-view-controller spring-roo

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

update.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=""/>

create.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"/>

Person.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));
        }
    }

0 个答案:

没有答案