Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

"No getter method for property ..." error

 
Tony Walters
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your jsp uses viewFullBio.do but your struts-config snippet is for addBio.do.
 
Tony Walters
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I thought the viewFullBio.do page was where the form was being submitted to. Am I missing something?
 
sreenath reddy
Ranch Hand
Posts: 415
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic