Gundersen, Richard wrote:
Hi

Basic question sorry (looked all over but can't find the answer)

1) When validation fails for my 'username' textfield, the error message
is displayed ABOVE the text box.
Is it possible to have more fine-grained control over how to position
the error message. Ideally I would like it below (and in line with) the
text box.

2) If I enter an invalid value twice, the original message is still
there, so I have two 'username is invalid' messages on the screen now. I
know this is done by the javascript so I want to know the recommended
way of overriding this behaviour.

Thanks

I presume you're referring purely to client-side validation.

Struts2 includes a javascript file validation.js that includes most of the logic. It contains a simple for-loop that searches for the location to insert each validation message relative to the input. I think you'll need to create your own version of validation.js that changes this search algorithm.

The templates for the tags dictate the location of the validation messages (divs or table cells). The controlHeader.ftl file imported by all tags will need to be updated to the structure you prefer (ie. to include the relevant div after the input). See the struts2 documents on creating a custom template.

You may also need to edit the form.ftl file, or whatever, to make it import your validation.js file instead of the default.

#2 sounds like a bug in validation.js. I recall there is logic in there to detect if a validation message is already present and not show it again. It was buggy and may only be fixed in 2.1.x.

If you're referring to server side validation, the repeated message indicates the list of errors is not being cleared between invocations of the same each, which implies to action is validated twice for the same request or a new instance is not being created for each request (which is bad, and only possible if you're using spring and have incorrect spring config).

Hope that helps,
Jeromy Evans





---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to