简体   繁体   中英

JSF f:validateLength is processed after the converter, but need it before

I have a password inputfield where i have a md5 converter on it. The field is binded with my entity.password field (that is stored as an md5 hash).

I want to set a f:validateLength on it so a password must have a certain length. Problem is that a "" empty String has also an md5 hash. The validator doesn't check the actual input but the converted md5 hash.

Can i set the validator on the actual input, not the converted one?

<ice:inputSecret value="#{user.employer.user.password}" converter="md5hashconverter">
 <f:validateLength minimum="3" maximum="15"/>
</ice:inputSecret>

Thank you

Edit: I'm using Hibernate and my backing bean is also the "model" managed bean. I persist with EntityManager.

You can't.

To me, this is also not really the right place to do the hash. It's not a "conversion" (which is supposed to be 2-way). Rather do it at the data access layer, either yourself right prior to INSERT , or just by grabbing the DB's builtin functions. Most of them provides sort of MD5() function which you can just use in your query like INSERT INTO user (name, pass) VALUES (?, MD5(?)) .

Edit : as per the update, you're using Hibernate JPA. In this case you can either use JPQL to fire a "plain" save query with MD5() function inside, or to grab an EntityListener ( guide here ) and act on @PrePersist and maybe also @PreUpdate .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM