1

The question is: is it a good way of programming using the method addFieldError OUTSIDE the validate method? Suppose that:

  • my validate method only checks if some textfields are empty or not, and if they are, my addFieldError makes some fieldErrors to show up.

  • my execute method, after processed the login request by calling a method of the right Java Bean, knowing that the username and/or the password were incorrect, needs to call addFieldError with an appropriate error message.

Of course, that the execute method will return INPUT in case of wrong username/password and SUCCESS if Log in was successful.

Is this approach okay?

Roman C
  • 49,761
  • 33
  • 66
  • 176
jomicobasi
  • 117
  • 1
  • 2
  • 11

1 Answers1

2

It would make not much sense to write the field error wrong username aside the username textfield, or wrong password aside the password textfield, because one of them may be correct, and you can't know (or better, should not let user know) which one. Also it would be ugly to write two times the same message like username or password wrong...

In these cases, you should use Action Error:

addActionError("Username or password incorrect.");

And in (generally the top part of) your JSP page, check for it, and then display it correctly:

<s:if test="hasActionErrors()">
   <div class="feedError">
       <s:actionerrors />
   </div>
</s:if>

read more on this answer.

Community
  • 1
  • 1
Andrea Ligios
  • 49,480
  • 26
  • 114
  • 243