| Author |
"No getter method for property ..." error
|
Tony Walters
Ranch Hand
Joined: Feb 13, 2003
Posts: 54
|
|
Hi all I'm getting a "no getter method for property firstName of bean org.apache.struts.taglib.html.BEAN" error while processing the following page: // createBio.jsp <%@ taglib uri="/WEB-INF/tld/struts-bean.tld" prefix="bean" %> <%@ taglib uri="/WEB-INF/tld/struts-html.tld" prefix="html" %> <%@ taglib uri="/WEB-INF/tld/struts-logic.tld" prefix="logic" %> <%@ taglib uri="/WEB-INF/tld/struts-nested.tld" prefix="nested" %> <html:errors /> <html:form action="/viewFullBio.do" focus="firstName"> <html:text property="firstName" /> <html:text property="lastName" /> <html:submit /> </html:form> The obvious mistake (from reading around) is inappropriate naming of the fields/ accessors and mutators in the ActionForm, here it is: // BioForm.java /** * ActionForm to hold details of Bio (including Employments and Tracks). */ public class BioForm extends ActionForm { // The fields. private String id; private String firstName; private String lastName; private String gender; private String ethnicity; private String role; private List employments; private List tracks; // Accessors & mutators for the fields. public void setId(String id) {this.id = id;} public String getId() {return id;} public void setFirstName(String firstName) {this.firstName = firstName;} public String getFirstName() {return firstName;} public void setLastName(String lastName) {this.lastName = lastName;} public String getLastName() {return lastName;} public void setGender(String gender) {this.gender = gender;} public String getGender() {return gender;} public void setEthnicity(String ethnicity) {this.ethnicity = ethnicity;} public String getEthnicity() {return ethnicity;} public void setRole(String role) {this.role = role;} public String getRole() {return role;} public void setEmployments(List employments) {this.employments = employments;} public List getEmployments() {return employments;} public void setTracks(List tracks) {this.tracks = tracks;} public List getTracks() {return tracks;} /** * Reset the fields. */ public void reset() { id = null; firstName = null; lastName = null; gender = null; ethnicity = null; role = null; employments = null; tracks = null; } /** * Validate the fields. */ public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) { ActionErrors errors = new ActionErrors(); if(firstName == null || firstName.length() < 1) { errors.add("firstName", new ActionError("error.required")); } if(lastName == null || lastName.length() < 1) { errors.add("lastName", new ActionError("error.required")); } return errors; } } Here is the config: //struts-config.xml <action path="/addBio" type="steel.struts.controller.BioActions" name="bioForm" scope="request" validate="true" input="createBio.page" parameter="add"> <forward name="success" path="viewFullBio.page" /> </action> Any ideas/ suggestions gratefully received!
|
 |
Marc Peabody
pie sneak
Sheriff
Joined: Feb 05, 2003
Posts: 4725
|
|
|
Your jsp uses viewFullBio.do but your struts-config snippet is for addBio.do.
|
A good workman is known by his tools.
|
 |
Tony Walters
Ranch Hand
Joined: Feb 13, 2003
Posts: 54
|
|
|
I thought the viewFullBio.do page was where the form was being submitted to. Am I missing something?
|
 |
sreenath reddy
Ranch Hand
Joined: Sep 21, 2003
Posts: 415
|
|
Hi tony action should be /add... rather than view as stated earlier its not the req from where it comes .i hope u r getting what we mean
|
 |
Tony Walters
Ranch Hand
Joined: Feb 13, 2003
Posts: 54
|
|
|
Ok, I think its just that I have been missing something. This does now work. Not sure I completely understand it, but will go through it slowly. Thanks for the help!
|
 |
 |
|
|
subject: "No getter method for property ..." error
|
|
|