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!