Descriptions for each Field in Spring
I have a spring roo project and for each field in my entity I want to add some sort of description for it such that the user can see what kind of input is expected and how they should input it. What is the best way to go about doing this? I know I will probably have to do something in either HTML or javascript开发者_开发百科 but since I don't know too much about either. I've just been creating everything through the roo shell.
I don't know the command in the roo shell for this but here are the findings of some reverse engineering I've done:
Looking at the vote
example that Spring Roo is shipping with, the password i.e. input field section is showing a nice message. This along with all the other messages are grouped into src\main\webapp\WEB-INF\il8n\messages.properties
. The password message for instance in that props file is called security_login_form_password_message
. In the view (login.jspx
) this entry is read as follows:
<spring:message code="security_login_form_password_message" var="pwd_msg" htmlEscape="false" />
Considering the MVC architecture, the description you want to add to your field should be in your view (like you expected, you should put that in your html).
Your entity should only validate stuff like:
- Is the incoming data the right type?
- Is the incoming data the right size?
- (ex: if your entity is a VARCHAR 10 in the DB -- raise a validation exception if data.lentgh > 10)
etc...
All the messages you want to display in a web page should be bundled in a .properties. Theses properties can be created with locale suffix to support internationalization.
ex: mymessages.properties_US_en, mymessages.properties_CA_fr
My 2 cents
精彩评论