I have this question about the validator in the Struts2 framework.
Say I have the following,
Action Class: Book.java
Video.java
Book-validation.xml (with the following codes)
add.jsp
struts.xml
Now the question is, why does the validator validates the field "title" that in the Add Video section? Doesn't the validator only validate fields that
will be invoked by the addBook.action only?
I'm confused by how the validator works, (sorry I only picked up Struts 2 recently and has no prior experience with any J2EE framework) hopefully I can get some help from the Ranch.
Are you saying that if you click on the "Submit Media" button it's validating the title? I'm a little skeptical, since the Video class doesn't extend ActionSupport and shouldn't support validation at *all*.
The problem is whenever the "Submit Publication" button is clicked, the validator also validates the "title" field for the Video section. Which is something I don't understand.
Since the validation xml is named under "Book-validation.xml", isn't it suppose to validate only fields that belong to the Book action class? Or am I having the wrong concept, that the validation just looks at the field name in the jsp and validate it as long as it matches?
It's not validating the video title--it's displaying the validation message for book title, because you have no way of differentiating between the two title fields. S2 validation is field-based, not form-based. You have the same field name in two forms. The action's fieldErrors() map is at the page level (not form). So the <s:textfield> tag checks for "title" errors--which it finds. Twice.