File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes Problem in Client side validation using Struts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Problem in Client side validation using Struts" Watch "Problem in Client side validation using Struts" New topic

Problem in Client side validation using Struts

Sumit Bagga

Joined: Jun 07, 2005
Posts: 4
Dear Friends
I am a bidding Software Enggineer.I am facing a problem for the "client side" validation in Struts Framework. There are 2 problems viz:-

1. Script tag in comming to the JSP page but the scripting code is no there!!! Please refer the "/////client side html code//////" below

2. Connection Time out error is there after the validation plugin Please refer the "/////ERROR/////" below!!!

Pls suggest for the information provide below with respect to the code.
U can look for the JSP FILE, STRUts-config.xml, validation.xml,validator rules.xml , client side generated code and Connection Error.
As soon as possible


Sumit Bagga (SCJP 1.4)

///////////////////// Index.jsp /////////////////////

<%@ taglib uri="/WEB-INF/struts-bean-el.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html-el.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/tiles.tld" prefix="tiles" %>
<%@ page import="org.apache.commons.logging.Log" %>
<%@ page import="org.apache.commons.logging.LogFactory" %>

<%-- Get a reference to the logger for this class --%>
<% Log logger = LogFactory.getLog( this.getClass( ) ); %>

<% logger.debug( "This is a debug message from a jsp" ); %>

<title>Sumit Bagga</title>
<link href="<html:rewrite page="/rr.css" />" rel="stylesheet" type="text/css">
<html:javascript formName="/authorityForm" dynamicJavascript="true" staticJavascript="false"/>
<%@include file="header.jsp" %><br><br><br><br><br>
<html:form action="userAction" focus="id" onsubmit="return validateAuthorityForm(this);">

<td >User Id:</td>
<td><html:text property="id" /></td>
<td>Password :</td>
<td><html assword property="passwords"/></td>
<html:submit><bean:message key="button.submit"/></html:submit>


<%@include file="footer.jsp" %>

////////////////// Vaidation.xml ////////////////////////

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

<!DOCTYPE form-validation PUBLIC
"-//Apache Software Foundation//DTD Commons Validator Rules Configuration 1.1.3//EN"

<form name="authorityForm">
<field property="id"
<arg0 key="id.displayname"/>
<field property="passwords"
<arg0 key="passwords.displayname"/>

////////////////// validator-rules.xml /////////////////////////

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

<!DOCTYPE form-validation PUBLIC
"-//Apache Software Foundation//DTD Commons Validator Rules Configuration 1.1.3//EN"



<validator name="required"

function validateRequired(form) {
alert("called required");
var bValid = true;
var focusField = null;
var i = 0;
var fields = new Array();
oRequired = new required();
alert("called 1");
for (x in oRequired) {
var field = form[oRequired[x][0]];

if (field.type == 'text' ||
field.type == 'textarea' ||
field.type == 'select-one' ||
field.type == 'radio' ||
field.type == 'password') {

var value;
// get field's value
if (field.type == "select-one") {
var si = field.selectedIndex;
value = field.options[si].value;
} else {
value = field.value;

if (value == '') {

if (i == 0) {
focusField = field;
fields[i++] = oRequired[x][1];
bValid = false;
alert("called 2");
if (fields.length > 0) {
alert("called 3");
return bValid;



//////////////////// Struts-config.xml ////////////////////////

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

<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.1//EN"
"" >

<!-- Form Bean Definitions -->
<form-bean name="authorityForm" type="net.reumann.authorityForm"/>

<!-- Global forwards -->
<forward name="error" path="/"/>

<!-- Action Mapping Definitions -->

<action path="/userAction"

<controller processorClass="org.apache.struts.tiles.TilesRequestProcessor"/>

null="true" />

<plug-in className="org.apache.struts.tiles.TilesPlugin" >
<set-property property="definitions-config" value="/WEB-INF/tiles-defs.xml"/>
<set-property property="definitions-parser-validate" value="true" />
<set-property property="definitions-debug" value="2" />
<set-property property="definitions-parser-details" value="2" />
<set-property property="moduleAware" value="true" />

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

<link href="/rr.css;jsessionid=4CE3A3ECE60B37DCD1DFF934C001AD76" rel="stylesheet" type="text/css">


<center> <table border="0" cellspacing="0" cellpadding="0" topmargin=0>
<tr align="justify">
<td border="0">
<img src="/images/img.jpg;jsessionid=4CE3A3ECE60B37DCD1DFF934C001AD76">


<body background="images/background.jpg" bgproperties="fixed">

<form name="authorityForm" method="post" action="/sumit/do/userAction;jsessionid=4CE3A3ECE60B37DCD1DFF934C001AD76" onsubmit="return validateAuthorityForm(this);">

<td >User Id:</td>
<td><input type="text" name="id" value=""></td>
<td>Password :</td>
<td><input type="password" name="passwords" value=""></td>
<input type="submit" value="Submit">

<script type="text/javascript" language="JavaScript">
var focusControl = document.forms["authorityForm"].elements["id"];

if (focusControl.type != "hidden") {
// -->


<div id="divFooter" class="clFooter">
<table cellpadding="2" cellspacing="0" border="0" width="100%" bgcolor="#C53723">
<td align="left">
<a href="/copyright.jsp;jsessionid=4CE3A3ECE60B37DCD1DFF934C001AD76">Copyright © 2004-2005 </a>
<a href="/privacy.jsp;jsessionid=4CE3A3ECE60B37DCD1DFF934C001AD76">privacy policy</a> </td>



/////////////////////// Error ///////////////////////////
ERROR [Thread-1] ( - Connection timed out: connect Connection timed out: connect
at Method)
at Source)
at Source)
at Source)
at Source)
at Source)
at Source)
at Source)
at Source)
at<init>(Unknown Source)
at Source)
at Source)
at Source)
at Source)
at Source)
at Source)
at Source)
at Source)
at Source)
at Source)
at$DTDDispatcher.dispatch(Unknown Source)
at Source)
at Source)
at Source)
at Source)
at Source)
at org.apache.commons.digester.Digester.parse(
at org.apache.commons.validator.ValidatorResourcesInitializer.initialize(
at org.apache.struts.validator.ValidatorPlugIn.initResources(
at org.apache.struts.validator.ValidatorPlugIn.init(
at org.apache.struts.action.ActionServlet.initModulePlugIns(
at org.apache.struts.action.ActionServlet.init(
at javax.servlet.GenericServlet.init(
at org.apache.catalina.core.StandardWrapper.loadServlet(
at org.apache.catalina.core.StandardWrapper.load(
at org.apache.catalina.core.StandardContext.loadOnStartup(
at org.apache.catalina.core.StandardContext.start(
at org.apache.catalina.core.ContainerBase.addChildInternal(
at org.apache.catalina.core.ContainerBase.addChild(
at org.apache.catalina.core.StandardHost.addChild(
at org.apache.catalina.startup.HostConfig.deployDirectory(
at org.apache.catalina.startup.HostConfig.deployDirectories(
at org.apache.catalina.startup.HostConfig.deployApps(
at org.apache.catalina.startup.HostConfig.start(
at org.apache.catalina.startup.HostConfig.lifecycleEvent(
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(
at org.apache.catalina.core.ContainerBase.start(
at org.apache.catalina.core.StandardHost.start(
at org.apache.catalina.core.ContainerBase.start(
at org.apache.catalina.core.StandardEngine.start(
at org.apache.catalina.core.StandardService.start(
at org.apache.catalina.core.StandardServer.start(
at org.apache.catalina.startup.Catalina.start(
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(
at org.apache.catalina.startup.Bootstrap.main(


Sumit Bagga<br />(SCJP 1.4)
loafer wang

Joined: May 20, 2008
Posts: 1
I hava the same to program,I also couldn't do !
K Kiran Kumar
Ranch Hand

Joined: Jan 04, 2006
Posts: 109
Hi Sumit,

1) You can try out keeping the below inside the <head> of your html

<html:javascript formName="AuthorityForm" />

Try out by not giving the attribute "name" in the form tag. You have used onsubmit="return validateAuthorityForm(this);">
Just remove the ";" in the onsubmit attribute. Keep trying with different tags and settings.

[ May 21, 2008: Message edited by: K Kiran Kumar ]
I agree. Here's the link:
subject: Problem in Client side validation using Struts