This week's book giveaways are in the Cloud and AI/ML forums.
We're giving away four copies each of Cloud Native Patterns and Natural Language Processing and have the authors on-line!
See this thread and this one for details.
Win a copy of Cloud Native PatternsE this week in the Cloud forum
or Natural Language Processing in the AI/ML forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Problem with struts messages

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was doing validation with struts(Client side). It does the validation but does not display the message. What cud be the reason?

I've my files here:
1)index.jsp
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Guest House System</title>
<link rel="STYLESHEET" type="text/css" href="css/touching4.css"/>
</head>
<body bgcolor="#FAF2D4">
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<html:errors/>
<html:form action="/find" focus="loginname" onsubmit="return validateLoginForm(this)">
<table border="0" cellspacing="0" cellpadding="0" align="center">
<tr class="versionbg">
<td>
<div class="versionaligb"><img src="Images/***1.jpg" alt="" width="100%"/></div>
</td>
</tr>
</table>
<Table border="5" align="Center">
<TR><TH CLASS="TITLE">Welcome to Guest House System</TH>
<tr align="Center">
<td>
<h1>Login Name: <html:text property="loginname"/></h1></br>
<h1>Password: <html assword property="password"/></h1></br>
<html:submit>Login</html:submit>
</td>
</tr>
</table>
</html:form>
<html:javascript formName="LoginForm" />
</body>
</html>

2)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>

<data-sources>

</data-sources>

<!-- ========== Form Bean Definitions =================================== -->
<form-beans>

<form-bean name="detailForm"
type="dk.hansen.DetailForm"/>
<form-bean name="LoginForm"
type="dk.hansen.LoginForm"/>

</form-beans>

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

<action path="/list"
type="dk.hansen.ListDVDAction"
input="/error.jsp">
<forward name="list" path="/list.jsp"/>
</action>

<action path="/detail"
type="dk.hansen.DetailDVDAction"
name="detailForm"
validate="false"
scope="request">
<forward name="detail" path="/detail.jsp"/>
</action>

<action path="/process"
type="dk.hansen.ProcessDVDAction"
name="detailForm"
scope="request"
validate="false">
<forward name="create" path="/create.do"/>
<forward name="update" path="/update.do"/>
<forward name="delete" path="/delete.do"/>
<forward name="cancel" path="/cancel.do"/>
</action>

<action path="/create"
type="dk.hansen.CreateDVDAction"
name="detailForm"
input="/detail.jsp"
scope="request">
<forward name="OK" path="/detail.jsp"/>
</action>

<action path="/update"
type="dk.hansen.UpdateDVDAction"
name="detailForm"
input="/detail.jsp"
scope="request">
<forward name="OK" path="/detail.jsp"/>
</action>

<action path="/delete"
type="dk.hansen.DeleteDVDAction"
name="detailForm"
scope="request"
validate="false">
<forward name="OK" path="/detail.jsp"/>
</action>
<action path="/cancel"
type="dk.hansen.ListDVDAction"
name="detailForm"
scope="request"
validate="false">
<forward name="list" path="/list.jsp"/>

</action>

<action path="/find"
type="dk.hansen.ListDVDAction"
name="LoginForm"
scope="request"
validate="true"
input="/index.jsp">
<forward name="admin" path="/jsp/admin.jsp"/>
<forward name="reception" path="/jsp/reception.jsp"/>
<forward name="reports" path="/jsp/reports.jsp"/>
<forward name="system" path="/jsp/system.jsp"/>
<forward name="adrec" path="/jsp/adrec.jsp"/>
<forward name="adsys" path="/jsp/adsys.jsp"/>
<forward name="adrep" path="/jsp/adrep.jsp"/>
<forward name="recrep" path="/jsp/recrep.jsp"/>
<forward name="recsys" path="/jsp/recsys.jsp"/>
<forward name="repsys" path="/jsp/repsys.jsp"/>
<forward name="adrecrep" path="/jsp/adrecrep.jsp"/>
<forward name="adrecsys" path="/jsp/adrecsys.jsp"/>
<forward name="reprecsys" path="/jsp/reprecsys.jsp"/>
<forward name="adreprecsys" path="/jsp/adrecrepsys.jsp"/>
<forward name="fail" path="/index.jsp"/>
<forward name="no" path="/jsp/show.jsp"/>
</action>

</action-mappings>

<message-resources parameter="MessageResources"/>

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

3)validaton.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="LoginForm">
<field
property="loginname"
depends="required">
<arg0 key="LoginForm.loginname"/>
</field>
<field
property="password"
depends="required,mask">
<arg0 key="LoginForm.password"/>
<var>
<var-name>mask</var-name>
<var-value>^[0-9a-zA-Z]*$</var-value>
</var>
</field>
</form>

</formset>
</form-validation>

4)validator-rules.xml
<!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">
<!--
$Header: /home/cvs/jakarta-struts/conf/share/validator-rules.xml,v 1.52 2004/07/25 12:00:20 niallp Exp $
$Revision: 1.52 $
$Date: 2004/07/25 12:00:20 $

This file contains the default Struts Validator pluggable validator
definitions. It should be placed somewhere under /WEB-INF and
referenced in the struts-config.xml under the plug-in element
for the ValidatorPlugIn.

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

These are the default error messages associated with
each validator defined in this file. They should be
added to your projects ApplicationResources.properties
file or you can associate new ones by modifying the
pluggable validators msg attributes in this file.

# Struts Validator Error Messages
errors.required={0} is required.
errors.minlength={0} can not be less than {1} characters.
errors.maxlength={0} can not be greater than {1} characters.
errors.invalid={0} is invalid.

errors.byte={0} must be a byte.
errors.short={0} must be a short.
errors.integer={0} must be an integer.
errors.long={0} must be a long.
errors.float={0} must be a float.
errors.double={0} must be a double.

errors.date={0} is not a date.
errors.range={0} is not in the range {1} through {2}.
errors.creditcard={0} is an invalid credit card number.
errors.email={0} is an invalid e-mail address.

Note: Starting in Struts 1.2.0 the default javascript definitions have
been consolidated to commons-validator. The default can be overridden
by supplying a <javascript> element with a CDATA section, just as
in struts 1.1.

-->

<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.ActionMessages,
javax.servlet.http.HttpServletRequest"
msg="errors.required"/>

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

<validator name="validwhen"
msg="errors.required"
classname="org.apache.struts.validator.validwhen.ValidWhen"
method="validateValidWhen"
methodParams="java.lang.Object,
org.apache.commons.validator.ValidatorAction,
org.apache.commons.validator.Field,
org.apache.struts.action.ActionMessages,
org.apache.commons.validator.Validator,
javax.servlet.http.HttpServletRequest"/>


<validator name="minlength"
classname="org.apache.struts.validator.FieldChecks"
method="validateMinLength"
methodParams="java.lang.Object,
org.apache.commons.validator.ValidatorAction,
org.apache.commons.validator.Field,
org.apache.struts.action.ActionMessages,
javax.servlet.http.HttpServletRequest"
depends=""
msg="errors.minlength"
jsFunction="org.apache.commons.validator.javascript.validateMinLength"/>


<validator name="maxlength"
classname="org.apache.struts.validator.FieldChecks"
method="validateMaxLength"
methodParams="java.lang.Object,
org.apache.commons.validator.ValidatorAction,
org.apache.commons.validator.Field,
org.apache.struts.action.ActionMessages,
javax.servlet.http.HttpServletRequest"
depends=""
msg="errors.maxlength"
jsFunction="org.apache.commons.validator.javascript.validateMaxLength"/>



<validator name="mask"
classname="org.apache.struts.validator.FieldChecks"
method="validateMask"
methodParams="java.lang.Object,
org.apache.commons.validator.ValidatorAction,
org.apache.commons.validator.Field,
org.apache.struts.action.ActionMessages,
javax.servlet.http.HttpServletRequest"
depends=""
msg="errors.invalid"/>


<validator name="byte"
classname="org.apache.struts.validator.FieldChecks"
method="validateByte"
methodParams="java.lang.Object,
org.apache.commons.validator.ValidatorAction,
org.apache.commons.validator.Field,
org.apache.struts.action.ActionMessages,
javax.servlet.http.HttpServletRequest"
depends=""
msg="errors.byte"
jsFunctionName="ByteValidations"/>


<validator name="short"
classname="org.apache.struts.validator.FieldChecks"
method="validateShort"
methodParams="java.lang.Object,
org.apache.commons.validator.ValidatorAction,
org.apache.commons.validator.Field,
org.apache.struts.action.ActionMessages,
javax.servlet.http.HttpServletRequest"
depends=""
msg="errors.short"
jsFunctionName="ShortValidations"/>


<validator name="integer"
classname="org.apache.struts.validator.FieldChecks"
method="validateInteger"
methodParams="java.lang.Object,
org.apache.commons.validator.ValidatorAction,
org.apache.commons.validator.Field,
org.apache.struts.action.ActionMessages,
javax.servlet.http.HttpServletRequest"
depends=""
msg="errors.integer"
jsFunctionName="IntegerValidations"/>



<validator name="long"
classname="org.apache.struts.validator.FieldChecks"
method="validateLong"
methodParams="java.lang.Object,
org.apache.commons.validator.ValidatorAction,
org.apache.commons.validator.Field,
org.apache.struts.action.ActionMessages,
javax.servlet.http.HttpServletRequest"
depends=""
msg="errors.long"/>


<validator name="float"
classname="org.apache.struts.validator.FieldChecks"
method="validateFloat"
methodParams="java.lang.Object,
org.apache.commons.validator.ValidatorAction,
org.apache.commons.validator.Field,
org.apache.struts.action.ActionMessages,
javax.servlet.http.HttpServletRequest"
depends=""
msg="errors.float"
jsFunctionName="FloatValidations"/>

<validator name="double"
classname="org.apache.struts.validator.FieldChecks"
method="validateDouble"
methodParams="java.lang.Object,
org.apache.commons.validator.ValidatorAction,
org.apache.commons.validator.Field,
org.apache.struts.action.ActionMessages,
javax.servlet.http.HttpServletRequest"
depends=""
msg="errors.double"/>


<validator name="date"
classname="org.apache.struts.validator.FieldChecks"
method="validateDate"
methodParams="java.lang.Object,
org.apache.commons.validator.ValidatorAction,
org.apache.commons.validator.Field,
org.apache.struts.action.ActionMessages,
javax.servlet.http.HttpServletRequest"
depends=""
msg="errors.date"
jsFunctionName="DateValidations"/>


<validator name="intRange"
classname="org.apache.struts.validator.FieldChecks"
method="validateIntRange"
methodParams="java.lang.Object,
org.apache.commons.validator.ValidatorAction,
org.apache.commons.validator.Field,
org.apache.struts.action.ActionMessages,
javax.servlet.http.HttpServletRequest"
depends="integer"
msg="errors.range"/>


<validator name="floatRange"
classname="org.apache.struts.validator.FieldChecks"
method="validateFloatRange"
methodParams="java.lang.Object,
org.apache.commons.validator.ValidatorAction,
org.apache.commons.validator.Field,
org.apache.struts.action.ActionMessages,
javax.servlet.http.HttpServletRequest"
depends="float"
msg="errors.range"/>


<validator name="creditCard"
classname="org.apache.struts.validator.FieldChecks"
method="validateCreditCard"
methodParams="java.lang.Object,
org.apache.commons.validator.ValidatorAction,
org.apache.commons.validator.Field,
org.apache.struts.action.ActionMessages,
javax.servlet.http.HttpServletRequest"
depends=""
msg="errors.creditcard"/>


<validator name="email"
classname="org.apache.struts.validator.FieldChecks"
method="validateEmail"
methodParams="java.lang.Object,
org.apache.commons.validator.ValidatorAction,
org.apache.commons.validator.Field,
org.apache.struts.action.ActionMessages,
javax.servlet.http.HttpServletRequest"
depends=""
msg="errors.email"/>

<validator name="url"
classname="org.apache.struts.validator.FieldChecks"
method="validateUrl"
methodParams="java.lang.Object,
org.apache.commons.validator.ValidatorAction,
org.apache.commons.validator.Field,
org.apache.struts.action.ActionMessages,
javax.servlet.http.HttpServletRequest"
depends=""
msg="errors.url"/>

<!--
This simply allows struts to include the validateUtilities into a page, it should
not be used as a validation rule.
-->
<validator name="includeJavaScriptUtilities"
classname=""
method=""
methodParams=""
depends=""
msg=""
jsFunction="org.apache.commons.validator.javascript.validateUtilities"/>

</global>

</form-validation>

5)MessageResources.properties
# -- Custom messages for this application --
LoginForm.loginname=Loginname
LoginForm.password=password
# -- Standard errors --
errors.header=<UL>
errors.prefix=<LI><B><FONT COLOR="RED">
errors.suffix=</FONT></B></LI>
errors.footer=</UL>
# -- validator --
errors.invalid={0} is invalid.
errors.maxlength={0} cannot be greater than {1} characters.
errors.minlength={0} cannot be less than {1} characters.
errors.range={0} is not in the range {1} through {2}.
errors.required={0} is required.
errors.byte={0} must be a byte.
errors.date={0} is not a date.
errors.double={0} must be a double.
errors.float={0} must be an float.
errors.integer={0} must be an integer.
errors.long={0} must be a long.
errors.short={0} must be a short.
errors.creditcard={0} is not a valid credit card number.
errors.email={0} is an invalid email address.
# -- other --
errors.cancel=Operation cancelled.
errors.detail={0}
errors.general=The process did not complete. Details should follow.
errors.token=Request could not be completed. Operation is not in sequence.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Harini H B",
Please check your private messages regarding an important administrative matter.
-Ben
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!