3

i have a login form in Struts 2 which has username and password field. what i want is when user submit the form and if it is not a valid user, i want to show the error message in a dialogue box (instead of showing the error message in login form itself). Is there any tag available in struts 2 for this or somebody can point me to similar kind of brief example?

Roman C
  • 49,761
  • 33
  • 66
  • 176
M Sach
  • 33,416
  • 76
  • 221
  • 314
  • by dialogue you mean some sort of overlyay/lightox? and are you submitting your login form in usual way or by ajax.? – Umesh Awasthi Jul 21 '12 at 14:07
  • dialogue means kind of popup box.I am submitting the form in normal fashion as we do in struts 2 with action attribute – M Sach Jul 21 '12 at 14:10

1 Answers1

8

put this in your login page(you are returning here right, on invalid login?)

<script>
   <s:if test="hasActionErrors()">
        showDialog("<s:actionerror/>");
   </s:if>
function showDialog(msg){
  //your logic to show dialog goes here
}
</script>

Here is a post which explains how to design a notification similar to stack overflow. You can use this or any other modal dialog, there are many tutorials on how to show a modal dialog

Community
  • 1
  • 1
Anupam
  • 7,966
  • 3
  • 41
  • 63
  • Good solution, but **it will break** due to the markup generated (*and* also if the errors themselves contain double quotes). To make it work simply [use the code provided in this answer](http://stackoverflow.com/a/29793896/1654265). – Andrea Ligios May 13 '15 at 08:21