How to display error login message on dialog after spring validation

How to display error login message on dialog after spring validation

Hello to everybody! You are my last chance. I ask this question on few forum and have no answer yet.
My issue is how to display login error on the login dialog after I validate the user in spring security.
index jsp:

    <div id="dialog">
        <div id="tabs">
            <ul>
                <li><a href="#login">Login</a></li>
                <li><a href="#register">Register</a></li>
            </ul>
            <div id="login">
                <jsp:include page="login.jsp"/>
            </div>
            <div id="register">
                <jsp:include page="register.jsp"/>   
            </div>
        </div>
    </div>   

login jsp:

<form id="logingForm" action="j_spring_security_check" method="POST">
        <div id="loginForm" class="ui-widget-content" >
              <table>
                <tr>
                  <td align="right" width="100">User:</td>
                    <td width="100"><input type="text" name="j_username"/></td>
                 </tr>
                 <tr>
                    <td align="right" width="100">Password:</td>
                    <td width="100"><input type="password" name="j_password" /></td>
                 </tr>
              </table>
              <br>
              <input id="logInButton" type="button" value="SignIn" />
        </div>
    </form>    

js:

$(document).ready(function(){
    $("#button").click(function(){
        $('#dialog').dialog(
            {
                modal : true,
                resizable : false,
                closeOnEscape : true,
                width : 350,
                height : 350,
                open: function(){
                    $('#tabs').tabs();
                }
            }
        );
    });
});

$("#loginReguster").click(function(){
    $('#logingForm').submit();
});

I don't know how to prevent the dialog from closing before validate and if errors after the validation to display them. If no error to close it.

Thanks is advice!