File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes client side validation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "client side validation" Watch "client side validation" New topic
Author

client side validation

Jasdeep Singh
Greenhorn

Joined: Apr 03, 2012
Posts: 2
//Bean class

import org.apache.struts.validator.*;

public class Bean extends ValidatorForm
{
String user="";
String email="";
String pass="";
//all getter setter
}

///MessageResources.properties

inputForm.user=USER NAME
inputForm.email=E-MAIL ID
inputForm.pass=PASSWORD

errors.required={0}is required.

//validator.xml

<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE form-validation SYSTEM "http://jakarta.apache.org/commons/dtds/validator_1_1.dtd" PUBLIC "-//Apache Software Foundation//DTD Commons Validator Rules Configuration 1.1//EN">
<form-validation> -<formset>
<form name="Bean">
<field depends="required" property="user"><arg0 key="inputForm.user"/> </field>
<field depends="required" property="email"><arg0 key="inputForm.email"/> </field>
<field depends="required" property="pass"><arg0 key="inputForm.pass"/> </field>
</form> </formset> </form-validation


//struts-config
<?xml version="1.0" encoding="WINDOWS-1252"?>

<!DOCTYPE struts-config SYSTEM "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd" PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN">
-<struts-config>
<form-beans>
<form-bean type="bean.Bean" name="Bean"/>
</form-beans>
<action-mappings>
<action type="strutsvalidation.LoginAction" name="Bean" validate="true" input="/index.jsp" scope="request" path="/login">
<forward name="success" path="/success.jsp"/> </action>
</action-mappings>
<message-resources null="false" parameter="strutsvalidation.MessageResources"/>
<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml" property="pathnames"/>
</plug-in>
</struts-config>

//index.jsp

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@ page contentType="text/html;charset=windows-1252"%>
<%@taglib prefix="html" uri="http://jakarta.apache.org/struts/tags-html"%>
<%@taglib prefix="bean" uri="http://jakarta.apache.org/struts/tags-bean"%>
<html:html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252"/>
<title>index</title>
</head>
<body>
<html:errors/>
<html:form action="/login.do" method="POST" onsubmit="return validateBean(this);">

<bean:message key="inputForm.user"/> <html:text property="user"/><br/>
<bean:message key="inputForm.email"/><html:text property="email"/><br/>
<bean:message key="inputForm.pass"/><html:password property="pass"/><br/>
<html:submit>SUBMIT</html:submit>
</html:form>
<html:javascript formName="Bean"/>
</body>
</html:html>

//ERROR


500 Internal Server Error
java.lang.NullPointerException: Depends string "required" was not found in validator-rules.xml.
at org.apache.struts.taglib.html.JavascriptValidatorTag.doStartTag(JavascriptValidatorTag.java:348) at _index._jspService(_index.java:172)
[/index.jsp] at com.orionserver[Oracle Containers for J2EE 10g (10.1.3.5.0) ].http.OrionHttpJspPage.service(OrionHttpJspPage.java:59) at oracle.jsp.runtimev2.JspPageTable.compileAndServe(JspPageTable.java:735) at oracle.jsp.runtimev2.JspPageTable.service(JspPageTable.java:425) at oracle.jsp.runtimev2.JspServlet.internalService(JspServlet.java:594) at oracle.jsp.runtimev2.JspServlet.service(JspServlet.java:518) at javax.servlet.http.HttpServlet.service(HttpServlet.java:856) at com.evermind[Oracle Containers for J2EE 10g (10.1.3.5.0) ].server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:734) at com.evermind[Oracle Containers for J2EE 10g (10.1.3.5.0) ].server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:391) at com.evermind[Oracle Containers for J2EE 10g (10.1.3.5.0) ].server.http.HttpRequestHandler.doProcessRequest(HttpRequestHandler.java:908) at com.evermind[Oracle Containers for J2EE 10g (10.1.3.5.0) ].server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:458) at com.evermind[Oracle Containers for J2EE 10g (10.1.3.5.0) ].server.http.HttpRequestHandler.serveOneRequest(HttpRequestHandler.java:226) at com.evermind[Oracle Containers for J2EE 10g (10.1.3.5.0) ].server.http.HttpRequestHandler.run(HttpRequestHandler.java:127) at com.evermind[Oracle Containers for J2EE 10g (10.1.3.5.0) ].server.http.HttpRequestHandler.run(HttpRequestHandler.java:116) at oracle.oc4j.network.ServerSocketReadHandler$SafeRunnable.run(ServerSocketReadHandler.java:260) at oracle.oc4j.network.ServerSocketAcceptHandler.procClientSocket(ServerSocketAcceptHandler.java:234) at oracle.oc4j.network.ServerSocketAcceptHandler.access$700(ServerSocketAcceptHandler.java:29) at oracle.oc4j.network.ServerSocketAcceptHandler$AcceptHandlerHorse.run(ServerSocketAcceptHandler.java:879) at com.evermind[Oracle Containers for J2EE 10g (10.1.3.5.0) ].util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:298) at java.lang.Thread.run(Thread.java:595)
Shankar Tanikella
Ranch Hand

Joined: Jan 30, 2011
Posts: 329

Hi Jasdeep,

Welcome to JavaRanch!!!

Please use the code tags which is good to read.

Regarding the issue, try putting the html:javascript tag inside the html:form and try again. Something likeIf that doesn't work out post the _index.java (servlet code for your JSP) from your server cache.


Have Fun with Java
little,little.. little by little makes a lot..
Jasdeep Singh
Greenhorn

Joined: Apr 03, 2012
Posts: 2
Hello shankar...

thanks for replying but, it's still not working..

//here is the _index.java



public class _index extends com.orionserver.http.OrionHttpJspPage {


// ** Begin Declarations


// ** End Declarations

public void _jspService(HttpServletRequest request, HttpServletResponse response) throws java.io.IOException, ServletException {

response.setContentType( "text/html;charset=windows-1252");
/* set up the intrinsic variables using the pageContext goober:
** session = HttpSession
** application = ServletContext
** out = JspWriter
** page = this
** config = ServletConfig
** all session/app beans declared in globals.jsa
*/
PageContext pageContext = JspFactory.getDefaultFactory().getPageContext( this, request, response, null, true, JspWriter.DEFAULT_BUFFER, true);
// Note: this is not emitted if the session directive == false
HttpSession session = pageContext.getSession();
int __jsp_tag_starteval;
ServletContext application = pageContext.getServletContext();
JspWriter out = pageContext.getOut();
_index page = this;
ServletConfig config = pageContext.getServletConfig();
javax.servlet.jsp.el.VariableResolver __ojsp_varRes = (VariableResolver)new OracleVariableResolverImpl(pageContext);

try {


out.write(__oracle_jsp_text[0]);
out.write(__oracle_jsp_text[1]);
out.write(__oracle_jsp_text[2]);
out.write(__oracle_jsp_text[3]);
{
org.apache.struts.taglib.html.HtmlTag __jsp_taghandler_1=(org.apache.struts.taglib.html.HtmlTag)OracleJspRuntime.getTagHandler(pageContext,org.apache.struts.taglib.html.HtmlTag.class,"org.apache.struts.taglib.html.HtmlTag");
__jsp_taghandler_1.setParent(null);
__jsp_tag_starteval=__jsp_taghandler_1.doStartTag();
if (OracleJspRuntime.checkStartTagEval(__jsp_tag_starteval))
{
do {
out.write(__oracle_jsp_text[4]);
{
org.apache.struts.taglib.html.ErrorsTag __jsp_taghandler_2=(org.apache.struts.taglib.html.ErrorsTag)OracleJspRuntime.getTagHandler(pageContext,org.apache.struts.taglib.html.ErrorsTag.class,"org.apache.struts.taglib.html.ErrorsTag");
__jsp_taghandler_2.setParent(__jsp_taghandler_1);
__jsp_tag_starteval=__jsp_taghandler_2.doStartTag();
if (__jsp_taghandler_2.doEndTag()==javax.servlet.jsp.tagext.Tag.SKIP_PAGE)
return;
OracleJspRuntime.releaseTagHandler(pageContext,__jsp_taghandler_2,2);
}
out.write(__oracle_jsp_text[5]);
{
org.apache.struts.taglib.html.FormTag __jsp_taghandler_3=(org.apache.struts.taglib.html.FormTag)OracleJspRuntime.getTagHandler(pageContext,org.apache.struts.taglib.html.FormTag.class,"org.apache.struts.taglib.html.FormTag action method onsubmit");
__jsp_taghandler_3.setParent(__jsp_taghandler_1);
__jsp_taghandler_3.setAction("/login.do");
__jsp_taghandler_3.setMethod("POST");
__jsp_taghandler_3.setOnsubmit("return validateBean(this);");
__jsp_tag_starteval=__jsp_taghandler_3.doStartTag();
if (OracleJspRuntime.checkStartTagEval(__jsp_tag_starteval))
{
do {
out.write(__oracle_jsp_text[6]);
{
org.apache.struts.taglib.bean.MessageTag __jsp_taghandler_4=(org.apache.struts.taglib.bean.MessageTag)OracleJspRuntime.getTagHandler(pageContext,org.apache.struts.taglib.bean.MessageTag.class,"org.apache.struts.taglib.bean.MessageTag key");
__jsp_taghandler_4.setParent(__jsp_taghandler_3);
__jsp_taghandler_4.setKey("inputForm.user");
__jsp_tag_starteval=__jsp_taghandler_4.doStartTag();
if (__jsp_taghandler_4.doEndTag()==javax.servlet.jsp.tagext.Tag.SKIP_PAGE)
return;
OracleJspRuntime.releaseTagHandler(pageContext,__jsp_taghandler_4,3);
}
out.write(__oracle_jsp_text[7]);
{
org.apache.struts.taglib.html.TextTag __jsp_taghandler_5=(org.apache.struts.taglib.html.TextTag)OracleJspRuntime.getTagHandler(pageContext,org.apache.struts.taglib.html.TextTag.class,"org.apache.struts.taglib.html.TextTag property");
__jsp_taghandler_5.setParent(__jsp_taghandler_3);
__jsp_taghandler_5.setProperty("user");
__jsp_tag_starteval=__jsp_taghandler_5.doStartTag();
if (__jsp_taghandler_5.doEndTag()==javax.servlet.jsp.tagext.Tag.SKIP_PAGE)
return;
OracleJspRuntime.releaseTagHandler(pageContext,__jsp_taghandler_5,3);
}
out.write(__oracle_jsp_text[8]);
{
org.apache.struts.taglib.bean.MessageTag __jsp_taghandler_6=(org.apache.struts.taglib.bean.MessageTag)OracleJspRuntime.getTagHandler(pageContext,org.apache.struts.taglib.bean.MessageTag.class,"org.apache.struts.taglib.bean.MessageTag key");
__jsp_taghandler_6.setParent(__jsp_taghandler_3);
__jsp_taghandler_6.setKey("inputForm.email");
__jsp_tag_starteval=__jsp_taghandler_6.doStartTag();
if (__jsp_taghandler_6.doEndTag()==javax.servlet.jsp.tagext.Tag.SKIP_PAGE)
return;
OracleJspRuntime.releaseTagHandler(pageContext,__jsp_taghandler_6,3);
}
{
org.apache.struts.taglib.html.TextTag __jsp_taghandler_7=(org.apache.struts.taglib.html.TextTag)OracleJspRuntime.getTagHandler(pageContext,org.apache.struts.taglib.html.TextTag.class,"org.apache.struts.taglib.html.TextTag property");
__jsp_taghandler_7.setParent(__jsp_taghandler_3);
__jsp_taghandler_7.setProperty("email");
__jsp_tag_starteval=__jsp_taghandler_7.doStartTag();
if (__jsp_taghandler_7.doEndTag()==javax.servlet.jsp.tagext.Tag.SKIP_PAGE)
return;
OracleJspRuntime.releaseTagHandler(pageContext,__jsp_taghandler_7,3);
}
out.write(__oracle_jsp_text[9]);
{
org.apache.struts.taglib.bean.MessageTag __jsp_taghandler_8=(org.apache.struts.taglib.bean.MessageTag)OracleJspRuntime.getTagHandler(pageContext,org.apache.struts.taglib.bean.MessageTag.class,"org.apache.struts.taglib.bean.MessageTag key");
__jsp_taghandler_8.setParent(__jsp_taghandler_3);
__jsp_taghandler_8.setKey("inputForm.pass");
__jsp_tag_starteval=__jsp_taghandler_8.doStartTag();
if (__jsp_taghandler_8.doEndTag()==javax.servlet.jsp.tagext.Tag.SKIP_PAGE)
return;
OracleJspRuntime.releaseTagHandler(pageContext,__jsp_taghandler_8,3);
}
{
org.apache.struts.taglib.html.PasswordTag __jsp_taghandler_9=(org.apache.struts.taglib.html.PasswordTag)OracleJspRuntime.getTagHandler(pageContext,org.apache.struts.taglib.html.PasswordTag.class,"org.apache.struts.taglib.html.PasswordTag property");
__jsp_taghandler_9.setParent(__jsp_taghandler_3);
__jsp_taghandler_9.setProperty("pass");
__jsp_tag_starteval=__jsp_taghandler_9.doStartTag();
if (__jsp_taghandler_9.doEndTag()==javax.servlet.jsp.tagext.Tag.SKIP_PAGE)
return;
OracleJspRuntime.releaseTagHandler(pageContext,__jsp_taghandler_9,3);
}
out.write(__oracle_jsp_text[10]);
{
org.apache.struts.taglib.html.SubmitTag __jsp_taghandler_10=(org.apache.struts.taglib.html.SubmitTag)OracleJspRuntime.getTagHandler(pageContext,org.apache.struts.taglib.html.SubmitTag.class,"org.apache.struts.taglib.html.SubmitTag");
__jsp_taghandler_10.setParent(__jsp_taghandler_3);
__jsp_tag_starteval=__jsp_taghandler_10.doStartTag();
if (OracleJspRuntime.checkStartBodyTagEval(__jsp_tag_starteval))
{
out=OracleJspRuntime.pushBodyIfNeeded(pageContext,__jsp_taghandler_10,__jsp_tag_starteval,out);
do {
out.write(__oracle_jsp_text[11]);
} while (__jsp_taghandler_10.doAfterBody()==javax.servlet.jsp.tagext.BodyTag.EVAL_BODY_AGAIN);
out=OracleJspRuntime.popBodyIfNeeded(pageContext,out);
}
if (__jsp_taghandler_10.doEndTag()==javax.servlet.jsp.tagext.Tag.SKIP_PAGE)
return;
OracleJspRuntime.releaseTagHandler(pageContext,__jsp_taghandler_10,3);
}
out.write(__oracle_jsp_text[12]);
{
org.apache.struts.taglib.html.JavascriptValidatorTag __jsp_taghandler_11=(org.apache.struts.taglib.html.JavascriptValidatorTag)OracleJspRuntime.getTagHandler(pageContext,org.apache.struts.taglib.html.JavascriptValidatorTag.class,"org.apache.struts.taglib.html.JavascriptValidatorTag formName");
__jsp_taghandler_11.setParent(__jsp_taghandler_3);
__jsp_taghandler_11.setFormName("Bean");
__jsp_tag_starteval=__jsp_taghandler_11.doStartTag();
if (__jsp_taghandler_11.doEndTag()==javax.servlet.jsp.tagext.Tag.SKIP_PAGE)
return;
OracleJspRuntime.releaseTagHandler(pageContext,__jsp_taghandler_11,3);
}
out.write(__oracle_jsp_text[13]);
} while (__jsp_taghandler_3.doAfterBody()==javax.servlet.jsp.tagext.BodyTag.EVAL_BODY_AGAIN);
}
if (__jsp_taghandler_3.doEndTag()==javax.servlet.jsp.tagext.Tag.SKIP_PAGE)
return;
OracleJspRuntime.releaseTagHandler(pageContext,__jsp_taghandler_3,2);
}
out.write(__oracle_jsp_text[14]);
} while (__jsp_taghandler_1.doAfterBody()==javax.servlet.jsp.tagext.BodyTag.EVAL_BODY_AGAIN);
}
if (__jsp_taghandler_1.doEndTag()==javax.servlet.jsp.tagext.Tag.SKIP_PAGE)
return;
OracleJspRuntime.releaseTagHandler(pageContext,__jsp_taghandler_1,1);
}

}
catch (Throwable e) {
if (!(e instanceof javax.servlet.jsp.SkipPageException)){
try {
if (out != null) out.clear();
}
catch (Exception clearException) {
}
pageContext.handlePageException(e);
}
}
finally {
OracleJspRuntime.extraHandlePCFinally(pageContext, true);
JspFactory.getDefaultFactory().releasePageContext(pageContext);
}

}
private static final char __oracle_jsp_text[][]=new char[15][];
static {
try {
__oracle_jsp_text[0] =
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n\"http://www.w3.org/TR/html4/loose.dtd\">\n".toCharArray();
__oracle_jsp_text[1] =
"\n".toCharArray();
__oracle_jsp_text[2] =
"\n".toCharArray();
__oracle_jsp_text[3] =
"\n".toCharArray();
__oracle_jsp_text[4] =
"\n <head>\n <meta http-equiv=\"Content-Type\" content=\"text/html; charset=windows-1252\"/>\n <title>index</title>\n </head>\n <body>\n ".toCharArray();
__oracle_jsp_text[5] =
"\n ".toCharArray();
__oracle_jsp_text[6] =
"\n \n ".toCharArray();
__oracle_jsp_text[7] =
" ".toCharArray();
__oracle_jsp_text[8] =
"<br/>\n ".toCharArray();
__oracle_jsp_text[9] =
"<br/>\n ".toCharArray();
__oracle_jsp_text[10] =
"<br/>\n ".toCharArray();
__oracle_jsp_text[11] =
"SUBMIT".toCharArray();
__oracle_jsp_text[12] =
"\n ".toCharArray();
__oracle_jsp_text[13] =
"\n ".toCharArray();
__oracle_jsp_text[14] =
"\n \n </body>\n".toCharArray();
}
catch (Throwable th) {
System.err.println(th);
}
}
}
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: client side validation