Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Validating forms

 
janice ang
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've tried to validate my fields with the below codes. However, the error message does not show up. Why is that so?

public class RegistrationFormBean extends org.apache.struts.action.ActionForm {

private String email;

public String getEmail() {
return (email);
}

public void setEmail(String email) {
this.email = email;
}

private String password;

public String getPassword() {
return (password);
}

public void setPassword(String password) {
this.password = password;
}

private String password2;

public String getPassword2() {
return (password2);
}

public void setPassword2(String password2) {
this.password2 = password2;
}

private String name;

public String getName() {
return (name);
}

public void setName(String name) {
this.name = name;
}


private String randomAssignTeam;

public String getRandomAssignTeam() {
return (randomAssignTeam);
}

public void setRandomAssignTeam(String randomAssignTeam) {
this.randomAssignTeam = randomAssignTeam;
}

private String seekMembers;

public String getSeekMembers() {
return (seekMembers);
}

public void setSeekMembers(String seekMembers) {
this.seekMembers = seekMembers;
}

private String term;

public String getTerm() {
return (term);
}

public void setTerm(String term) {
this.term = term;
}

private String skills;

public String getSkills() {
return (skills);
}

public void setSkills(String skills) {
this.skills = skills;
}

private String remarks;

public String getRemarks() {
return (remarks);
}

public void setRemarks(String remarks) {
this.remarks = remarks;
}

public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
ActionErrors errors = new ActionErrors();
if (getEmail() == null || getEmail().length() < 1) {
errors.add("email", new ActionMessage("error.Registration.email.required"));
}
if (getEmail() != null && getEmail().indexOf('@')==-1) {
errors.add("emailValidity", new ActionMessage("error.Registration.email.notvalid"));
}
if (getName() == null || getName().length() < 1) {
errors.add("studentName", new ActionMessage("error.Registration.name.required"));
}
if (getPassword() == null || getPassword().length() < 1 || getPassword2() == null || getPassword2().length() < 1 || !getPassword().equals(getPassword2())) {
errors.add("password", new ActionMessage("error.Registration.password.required"));
}
if (getTerm() == null || getTerm().length() < 1) {
errors.add("term", new ActionMessage("error.Registration.term.required"));
}

return errors;
}

public void reset() {
this.email = null;
this.password = null;
this.password2 = null;
this.name = null;
this.randomAssignTeam = null;
this.term = null;
this.skills = null;
this.remarks = null;
}

}

In my Message Properties, I've included:

error.Registration.email.required=Please enter the email address.
error.Registration.name.required=Please enter the name.
error.Registration.password.required=Both password field is required. Make sure their value are the same.
error.Registration.email.notvalid=Please use a valid email address.
error.Registration.term.notvalid=Please select the term you want to take IS480.


Anywhere gone wrong?
 
Christian Nash
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
have you added <html:errors/> in your jsp (wherever you need to display the errors if thats what you want)? this may be the reason..otherwise please specify what errors you're getting if any.
[ April 09, 2007: Message edited by: Christian Nash ]
 
janice ang
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

yup, i'v added <html:error/> when i click on the submit button, it only display:
-
-
-
-
-

that's all on the registration page. i think it recognized my fields but it just fail to display the error message.
[ April 09, 2007: Message edited by: janice ang ]
 
Christian Nash
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the tag should be <html:errors/> and not <html:error/>..if you still not able to display please give your jsp and struts config file.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic