Question : Validation framework not working for login screen

I am really getting frustrated in making the validation framework work for my login screen.

I have done almost all the things correctly but could not figure where i have gone wrong.
Below contain my struts-config.xml file

Below is the content of validation.xml file


<form-validation>
    <formset>
        <!-- An example form -->
        <form name="loginForm">
            <field property="username" depends="required">
                 <arg bundle="label" key="label.login.username"/>
            </field>
        </form>

    </formset>

</form-validation>

next is the content of login.jsp page.

It will be great if someone could identify the mistake i have made. Currently when i click login button without entering anything in the username field nothing happens. I currently expect validation error message to be displayed for not entering the username
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
<!-- ================================================ Form Bean Definitions -->

    <form-beans>
	<form-bean 
		name="loginForm"
		type="com.attragroup.tcr.forms.LoginForm" />
    </form-beans>


<!-- =========================================== Action Mapping Definitions -->

    <action-mappings>
            <!-- Default "Welcome" action -->
            <!-- Forwards to Welcome.jsp -->
        <action path="/login" type="com.attragroup.tcr.action.LoginAction" name="loginForm" scope="request" validate="true" input="/login.jsp"/>
        <action path="/authenticate" type="com.attragroup.tcr.action.AuthenticateProjectAction" />
        <action path="/Welcome" forward="/pages/Welcome.jsp" />

    </action-mappings>


<!-- ======================================== Message Resources Definitions -->

    <message-resources parameter="com.attragroup.tcr.settings.MessageResources"/>
    <message-resources parameter="com.attragroup.tcr.settings.LabelResources"  key="label" />



  <!-- =================================================== Validator plugin -->

    <plug-in className="org.apache.struts.validator.ValidatorPlugIn">
        <set-property property="pathnames" value="/org/apache/struts/validator/validator-rules.xml,
           /WEB-INF/validation.xml" />
    </plug-in>

</struts-config>
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
Login.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1" errorPage="error.jsp"%>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<!doctype html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Attra Test Case Repository</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="js/shadedborder.js"></script>
<script type="text/javascript" src="js/ajax.js"> </script>
<link href="css/style.css" rel="stylesheet" type="text/css">
</head>
<body>
<html:form action="/login" method="POST">

<div id="content">
  <div id="innerholder">
    <h3><span></span></h3>
        	<div>
            	<div id="usernamelbl"><b><bean:message bundle="label" key="label.login.username"/> :</b></div>
                <div class="roundedfield" >
                	<html:text property="username" styleId="username"/>  
                </div>
            </div>
            <div>
                <div id="passwordlbl"><b><bean:message bundle="label" key="label.login.password"/> :</b></div>
                <div class="roundedfield" >
                <html:password property="password" styleId="password"/>
                </div>    
            </div>
            <div>
                <div id="projectlbl"><b><bean:message bundle="label" key="label.login.project"/> :</b></div>
                <div class="nonroundedfield">
                <html:select property="project"><html:option value=""></html:option></html:select> 
                </div>    
            </div>
            <br />
            <html:button property="authenticatebutton" onclick="authenticate();" styleId="authenticatebutton">
            <bean:message bundle="label" key="btn.login.authenticate"/></html:button> 
            <html:submit property="loginbutton" styleId="loginbutton">
            <bean:message bundle="label" key="btn.login.login"/></html:submit>
<font color="red">
<html:errors/>
</font> 
  </div>
</div>
</html:form>
<script language="javascript" type="text/javascript">  
    holderBorder.render('content');
</script>
</body>
</html>

Answer : Validation framework not working for login screen

I have resolved the issue. There was a invalid <form-bean/> tag in the struts config file.
Random Solutions  
 
programming4us programming4us