• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Validation method in lookup form

 
Lalit Vora
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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


****************LookupForm.java**************

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();

else
{
SimpleDateFormat format = new SimpleDateFormat(dateFormat);
format.setLenient(false);
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"));

}

}


*************************messageresouce.property*************

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

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
Lalit
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you included an <html:errors /> tag in your JSP? If not, that's the problem.
 
Lalit Vora
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
messageresouce.property


<message-resources parameter="MessageResources" />


Shouldn't this be:



Try it out
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic