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