This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
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


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Problem in Client side validation using Struts" Watch "Problem in Client side validation using Struts" New topic
Author

Problem in Client side validation using Struts

Sumit Bagga
Greenhorn

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

Thanks

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" ); %>

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

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



</html:form>

</center>
</body>
<%@include file="footer.jsp" %>
</html:html>

////////////////// 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"
"http://jakarta.apache.org/commons/dtds/validator_1_1_3.dtd">

<form-validation>
<formset>
<form name="authorityForm">
<field property="id"
depends="required">
<arg0 key="id.displayname"/>
</field>
<field property="passwords"
depends="required">
<arg0 key="passwords.displayname"/>
</field>
</form>
</formset>
</form-validation>

////////////////// 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"
"http://jakarta.apache.org/commons/dtds/validator_1_1_3.dtd">

<form-validation>

<global>

<validator name="required"
classname="org.apache.struts.validator.FieldChecks"
method="validateRequired"
methodParams="java.lang.Object,
org.apache.commons.validator.ValidatorAction,
org.apache.commons.validator.Field,
org.apache.struts.action.ActionErrors,
javax.servlet.http.HttpServletRequest"
msg="errors.required">

<javascript><![CDATA[
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) {
focusField.focus();
alert(fields.join('\n'));
}
alert("called 3");
return bValid;
}]]>
</javascript>

</validator>
</global>

</form-validation>

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

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

<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.1//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd" >
<struts-config>



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

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

<!-- Action Mapping Definitions -->
<action-mappings>

<action path="/userAction"
type="net.reumann.AuthorityAction"
name="authorityForm"
scope="request"
validate="true"
parameter="methodToCall"
input="index.page"
>
<forward
name="continue"
path="Front.page"/>
<forward
name="failure"
path="error.page"/>
</action>

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

<message-resources
parameter="ApplicationResources"
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>

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

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

</head>




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

</table></center>


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

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

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



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

if (focusControl.type != "hidden") {
focusControl.focus();
}
// -->
</script>


</center>
</body>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>




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

</tr>
</table>
</div>

</html>



/////////////////////// Error ///////////////////////////
ERROR [Thread-1] (ValidatorPlugIn.java:224) - Connection timed out: connect
java.net.ConnectException: Connection timed out: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(Unknown Source)
at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at sun.net.NetworkClient.doConnect(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.<init>(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.startEntity(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.startDTDEntity(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDTDScannerImpl.setInputSource(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$DTDDispatcher.dispatch(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)
at org.apache.commons.digester.Digester.parse(Digester.java:1567)
at org.apache.commons.validator.ValidatorResourcesInitializer.initialize(ValidatorResourcesInitializer.java:140)
at org.apache.struts.validator.ValidatorPlugIn.initResources(ValidatorPlugIn.java:222)
at org.apache.struts.validator.ValidatorPlugIn.init(ValidatorPlugIn.java:161)
at org.apache.struts.action.ActionServlet.initModulePlugIns(ActionServlet.java:1156)
at org.apache.struts.action.ActionServlet.init(ActionServlet.java:472)
at javax.servlet.GenericServlet.init(GenericServlet.java:211)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1091)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:925)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:3857)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4118)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:759)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:739)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:524)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:894)
at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:857)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:475)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1102)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1020)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:718)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1012)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:442)
at org.apache.catalina.core.StandardService.start(StandardService.java:450)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:683)
at org.apache.catalina.startup.Catalina.start(Catalina.java:537)
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(Bootstrap.java:271)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:409)


</struts-config>


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

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.

Regards,
Kiran.
[ May 21, 2008: Message edited by: K Kiran Kumar ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem in Client side validation using Struts