Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes Struts and the fly likes Validation method in lookup form Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Validation method in lookup form" Watch "Validation method in lookup form" New topic

Validation method in lookup form

Lalit Vora
Ranch Hand

Joined: Jun 22, 2006
Posts: 37
Hi All,
I am not getting error message displayed in my jsp. Yes if i am not entering correct date its not moving ahead but not showing me message.

I want to do validation in lookupform My lookup form and message resource property file is as under. I commented following line because It says this method is deprecated
//errors.add("Recdt", new ActionError("error.recdt"));

But it has following method
errors.add("Report Name", new ActionMessage("error.repname")); Here i am not sure in this method parameters are right or not. please suggest me. Where to keep my message resource property file. I was able to run with deprecated method before when i used myeclipse j2ee project and added struts library.

Below is my files please guide me


public class LookupForm extends ActionForm


private String reptype = null;
public String getReptype()
return (this.reptype);
public void setReptype(String reptype)
this.reptype = reptype;

private String repname = null;
public String getRepname() {
return (this.repname);
public void setRepname(String repname) {
this.repname = repname;

private String recdt = null;
public String getRecdt() {
return (this.recdt);
public void setRecdt(String recdt) {
this.recdt = recdt;

public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request) {
// Log the forms data
servlet.log("Reptype:" + reptype);
servlet.log("Repname:" + repname);
servlet.log("Recdt:" + recdt);

// Check for mandatory data
ActionErrors errors = new ActionErrors();

if (repname == null || repname.equals("") || repname.equals("one")) {
//errors.add("Report Type", new ActionError("error.reptype"));
errors.add("Report Type",new ActionMessage("error.reptype"));


if (reptype == null || reptype.equals("")) {
//errors.add("Report Name", new ActionError("error.repname"));
errors.add("Report Name", new ActionMessage("error.repname"));

int a;
String dateFormat = "MM/dd/yyyy";
int dateFormatLength = dateFormat.length();
try {

if (recdt.length() != dateFormatLength)
throw new Exception();

SimpleDateFormat format = new SimpleDateFormat(dateFormat);
Date theDate = new Date();
theDate = format.parse(recdt);
a =0;
System.out.println("valid date" +a);

catch(Exception e)

a = 1;
System.out.println("invalid date" +a);
if (a==1)
//errors.add("Recdt", new ActionError("error.recdt"));
errors.add("Recdt", new ActionMessage("error.recdt"));




errors.header=<h4>Validation Error(s)</h4><ul>

error.reptype=<li>Please Select Report Type
error.repname=<li>Please Select Report Name
error.recdt=<li>Please Enter Date in mm/dd/yyyy format

I have <message-resources parameter="MessageResources" />

</struts-config> mentioned in strutsd config.

Thank you very much
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Have you included an <html:errors /> tag in your JSP? If not, that's the problem.

Consultant, Sima Solutions
Lalit Vora
Ranch Hand

Joined: Jun 22, 2006
Posts: 37
yes i have that in index.jsp

i have two message resources file one in src--java folder
other in classes--java folder
where to keep my message resource property file?

why it came like // line errors.add..... deprecated?
am i doing anything wrong in using other method? that is AddErrorMessage line below // line
in argument or so?

Please guide me
Jaikiran Pai

Joined: Jul 20, 2005
Posts: 10441

<message-resources parameter="MessageResources" />

Shouldn't this be:

Try it out

[My Blog] [JavaRanch Journal]
I agree. Here's the link:
subject: Validation method in lookup form
It's not a secret anymore!