Struts2_bundle validation.xml not working



Hey guys i am new to struts2 & i am not able to find out my bug.I have already seen similar question but i didn't get success till now.


I am doing validation in struts2 using bundle_validators, but the problem is Validation is not done at RUNTIME when i execute the program.



my bean & validation.xml is in src/actions package-



My ActionLogin.java



package actions;

import com.opensymphony.xwork2.ActionSupport;

public class ActionLogin extends ActionSupport {

private String name,email,password;

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getEmail() {
return email;
}

public void setEmail(String email) {
this.email = email;
}

public String getPassword() {
return password;
}

public void setPassword(String password) {
this.password = password;
}

public String execute(){

return "success";
}




}


Register-validation.xml



<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE validators PUBLIC "-//OpenSymphony Group//XWork Validator 1.0.2//EN" "http://ift.tt/1dz82oz">




<validators>
<field name="name">
<field-validator type="requiredstring">
<param name="trim">true</param>
<message>User Name is required.</message>
</field-validator>
</field>

<field name="email">
<field-validator type="requiredstring">
<param name="trim">true</param>
<message>Email is required.</message>
</field-validator>
</field>

</validators>


My struts.xml is in WEB-INF/classes directory



<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD
Struts Configuration 2.1//EN" "http://ift.tt/1tkDVrF">



<struts>



<include file="struts-default.xml"/>

<constant name="struts.devMode" value="true" />
<package name="actions" namespace="/" extends="struts-default">

<action name="register" class="actions.ActionLogin" method="execute">



<result name="success">/welcome.jsp</result>
<result name="input">index.jsp</result>

</action>

</package>


</struts>


My index.jsp file is



<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>

<%@taglib uri="/struts-tags" prefix="s" %>
<%@taglib uri="/struts-dojo-tags" prefix="d" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://ift.tt/kTyqzh">
<html>
<head>
<STYLE type="text/css">
.errorMessage{color:red;}
</STYLE>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>



</head>
<body>

<s:form action="register">
<s:textfield name="name" label="name"></s:textfield>
<s:password name="password" label="Password"></s:password>
<s:textfield name="email" label="Email"></s:textfield>
<s:submit value="login"></s:submit>

</s:form>

</body>
</html>


Please help me find out my bug.Thanks in advance


No comments:

Post a Comment