T
teser3
I have a validate method in a bean class that works and now I want to
condense it into a for loop.
Here is what I have:
//firstname and lastname are declared earlier
public boolean validate()
{
boolean allOk=true;
if (firstName.equals("")) {
errors.put("firstName","Please enter your first name");
allOk=false;
}
if (lastName.equals("")) {
errors.put("lastName","Please enter your last name");
allOk=false;
}
return allOk;
}
My attempt doesnt work because I cant seem to figure out how to put
the array reference in the key part of the errors.put method:
public boolean validate()
{
boolean allOk=true;
String [] myarray = {firstname, lastname}
for(int i=0;i < myarray.length;i++)
{
if (myarray.equals("")) {
errors.put(myarray,"Please enter your " + myarray);
allOk=false;
}
}
return allOk;
}
The results dont validate any of my data so I assume I have something
wrong with my array. Please advise.
condense it into a for loop.
Here is what I have:
//firstname and lastname are declared earlier
public boolean validate()
{
boolean allOk=true;
if (firstName.equals("")) {
errors.put("firstName","Please enter your first name");
allOk=false;
}
if (lastName.equals("")) {
errors.put("lastName","Please enter your last name");
allOk=false;
}
return allOk;
}
My attempt doesnt work because I cant seem to figure out how to put
the array reference in the key part of the errors.put method:
public boolean validate()
{
boolean allOk=true;
String [] myarray = {firstname, lastname}
for(int i=0;i < myarray.length;i++)
{
if (myarray.equals("")) {
errors.put(myarray,"Please enter your " + myarray);
allOk=false;
}
}
return allOk;
}
The results dont validate any of my data so I assume I have something
wrong with my array. Please advise.